If a user types in [[0,0,0], [0,0,1], [1,1,0]]
and press enter,
the program should convert this string to several lists;
one list holding [0][0][0]
, other for [0][0][1]
, and the last list for [1][1][0]
Does python have a good way to handle this?
>>> import ast
>>> ast.literal_eval('[[0,0,0], [0,0,1], [1,1,0]]')
[[0, 0, 0], [0, 0, 1], [1, 1, 0]]
For tuples
>>> ast.literal_eval('[(0,0,0), (0,0,1), (1,1,0)]')
[(0, 0, 0), (0, 0, 1), (1, 1, 0)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With