Skip to content Skip to sidebar Skip to footer

Python - Make A List

How can I turn something like this: (not a file) Edit: It's what I get when I print this: adjusted_coordinate_list = str(adjusted_X_coordinate) + ',' + str(Y_coordinate) 1,1 1,2 1

Solution 1:

Use str.splitlines to split over boundaries of string and needed a list.

s = """1,1
1,2
1,3
1,4
1,5"""print s.splitlines()

['1,1', '1,2', '1,3', '1,4', '1,5']

Solution 2:

It looks to me like you are looping over this command to get the input you described. I'm assuming something like this:

for foo in bar:
    adjusted_coordinate_list = str(adjusted_X_coordinate) + ',' + str(Y_coordinate)
    print adjusted_coordinate_list

In order to get all the results in a clean list, you would do something like this:

adjusted_coordinate_list = []
for foo in bar:
    new_elem = "%s,%s" % ( adjusted_X_coordinate, Y_coordinate )
    adjusted_coordinate_list.append( new_elem )

Your adjusted_coordinate_list will now contain a list of all the adjusted coordinates.

Solution 3:

Can try this pseudo code

ans_list = []
foreachrow:
    row= row.strip()
    ans_list.append(row)

Solution 4:

you try this:

my_cor =[]
#some loop
    my_cor.append(str(adjusted_X_coordinate) + ',' + str(Y_coordinate))
print my_cor

Post a Comment for "Python - Make A List"