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

What can cause "Required Package 'IndyCore' not found" when compiling a Delphi 2010 project? -

Change the color of an oval at click in Java AWT -