python - Coverting list of Coordinates to list of tuples -


i'm trying covert list of coordinates list of tuples:

from:

a_list = ['56,78','72,67','55,66'] 

to:

list_of_tuples = [(56,78),(72,67),(55,66)] 

i've tried doing for, in loop convert each element in a_list tuple output in form:

list_of_tuples = [('5', '6', '7', '8'), ('7', '2', '6', '7'), ('5', '5', '6', '6')]  

any on doing wrong here appreciated.

edit: fixed expected output, no spaces between coordinates , tuples.

you can use list comprehension:

result = [tuple(map(int,element.split(','))) element in a_list] 

edit: shorter version @lol4t0

as mentioned spaces between elements come printing list. there no actual "spaces" in data structure. however, if wish print list without spaces can do:

print str(result).replace(" ","") 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -