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
Post a Comment