python convert string of tuple into tuple code example
Example 1: python convert a string of tuples to a tuple of tuples
import ast
ast.literal_eval(your_string)
'(0,0,0), (0,0,1), (1,1,0)'
'((0,0,0), (0,0,1), (1,1,0))'
((0,0,0), (0,0,1), (1,1,0))
import ast
your_string = '(0,0,0), (0,0,1), (1,1,0)'
your_tuple = ast.literal_eval(your_string)
print(your_tuple)
--> ((0,0,0), (0,0,1), (1,1,0))
Example 2: python string to tuple
l = list('abcd')
l = map(None, 'abcd')
l = [i for i in 'abcd']
import re
l = re.findall('.', 'abcd')
print(l)