python convert a string of tuples to a tuple of tuples code example
Example: python convert a string of tuples to a tuple of tuples
# Basic syntax:
import ast
ast.literal_eval(your_string)
# Example usage:
# Say you want to convert a string like:
'(0,0,0), (0,0,1), (1,1,0)' # or like
'((0,0,0), (0,0,1), (1,1,0))'
# to a tuple of tuples like:
((0,0,0), (0,0,1), (1,1,0))
# Import the Abstract Syntax Trees package:
import ast
your_string = '(0,0,0), (0,0,1), (1,1,0)'
# Convert to tuple of tuples:
your_tuple = ast.literal_eval(your_string)
print(your_tuple)
--> ((0,0,0), (0,0,1), (1,1,0))