Jul-29-2019, 12:20 AM
Fist, this is not a homework problem. But I'm noob enough for it to be in that category.
Here the code:
The idea of all basic data being arrays is a bit new to me.
So the question is if there is a simpler way, perhaps using modules, of converting lists, and list of lists (multidimensional arrays) into simple string lists without that for(each) and join command?
Most of the scripts I would like to convert from Perl have int and strings mixed together (as strings) and it was easy to parse whatever I wanted (=~ /regex/ ) . Looking for similar, even if as extensions (modules) to the language. Being new, not very familiar with the standard libraries here!
Here the code:
#!/usr/bin/python3 # Example of function returning multidimensional array, and turning it into normal string list. def changeme( mylist, zylist ): yulist = [mylist[2],450,700,666] # Function vaqriables xulist = [zylist[0],zylist[2],3,4] # to change argument vars return( yulist, xulist ) # returns 2 lists - 2 dimensional array ########## End of function ### Function call mylist=[0,0,0,0,0,0] zylist=[1,1,1,1,1] newlist = (changeme(mylist,zylist)) # [[1,2,3][4,5,6]] format of two arrays(lists) ###################3 ###### Return processing print(newlist) #2 lists print(newlist[0]) # 1st list print(newlist[1]) # 2nd List numstring = ([str(y) for x in newlist for y in x]) # Converts num to string list in [1,2,3,...] order print(numstring) mynewstr = (' '.join(numstring)) # removes commas, so string in [ 1 2 3 ...] order print(mynewstr) ################## Non-functioning # print(str(newlist).strip('[]')) # print(str(newlist)[1:-1])There are acxtually no problems with the code itself. Coming from Perl, I am a bit aghast at what looks like some unexpected complexity, however.
The idea of all basic data being arrays is a bit new to me.
So the question is if there is a simpler way, perhaps using modules, of converting lists, and list of lists (multidimensional arrays) into simple string lists without that for(each) and join command?
Most of the scripts I would like to convert from Perl have int and strings mixed together (as strings) and it was easy to parse whatever I wanted (=~ /regex/ ) . Looking for similar, even if as extensions (modules) to the language. Being new, not very familiar with the standard libraries here!