python convert a string of tuples to a tuple of tuples

Solutions on MaxInterview for python convert a string of tuples to a tuple of tuples by the best coders in the world

showing results for - "python convert a string of tuples to a tuple of tuples"
Philipp
11 Aug 2020
1# Basic syntax:
2import ast
3ast.literal_eval(your_string)
4
5# Example usage:
6# Say you want to convert a string like:
7'(0,0,0), (0,0,1), (1,1,0)' # or like
8'((0,0,0), (0,0,1), (1,1,0))'
9# to a tuple of tuples like:
10((0,0,0), (0,0,1), (1,1,0))
11
12# Import the Abstract Syntax Trees package:
13import ast
14your_string = '(0,0,0), (0,0,1), (1,1,0)'
15
16# Convert to tuple of tuples:
17your_tuple = ast.literal_eval(your_string)
18print(your_tuple)
19--> ((0,0,0), (0,0,1), (1,1,0))
queries leading to this page
how to convert a string tuple to tuple in pythonstring to tuples pythonpython convert string of tuple to tuple objecthow to convert a string to a tuple in pythonhow to convert to tuplesstring of tuples to stringconverting a string to a tupleconvert tuple in string format to tuple pythonhow to convert strings into tuplesconverting a variable from string to tuple in pythonpython convert string to tupleconvert to tuple pythontuple str to tuple pythonconvert a string to a tuple in pythontuple string to tuple pythonconvert a string to a tuple pythonhow to convert string into tuple in pythonconvert a string to tuplemake tuples from string pythonhow to convert a string to tuple in pythonhow to turn string tuple into normal tuplemake tuples from stringconvert string tuple to tuple pythonconvert string of tuple to tuple pythonpython turn string tuple into tupleconvert string to tuples pythonconvert string in a from of a tuple to tuple pythonpython string of tuple to tupleconverting string tuple to a tuple pythonpython convert a string of tuples to a tuple of tuplesstring tuple to tuple pythonhow to convert string to tuple in pythonpython string tuple to tuplepython convert string tuple to tupleconverting a string to tuple in pythonconvert tuple string to tuple pythonpython tuple string to tuplepython convert string of tuple into tupleconverting string to tuple in pythonconvert a string to a tuplepython tuple to string with out 28 2cpython convert a string of tuples to a tuple of tuples