python - How to retrieve tuples from list of string tuples -


a=['(10,13)', '(23,45)', '(56,78)'] 

here each item in list a string

i want other list this:

b=[(10,13),(23,45),(56,78)] 

where each item tuple , each element in each tuple integer.

use ast.literal_eval , list comprehension:

>>> ast import literal_eval >>> = ['(10,13)', '(23,45)', '(56,78)'] >>> b = [literal_eval(x) x in a] >>> b [(10, 13), (23, 45), (56, 78)] >>> 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -