Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert this string to list of lists? [duplicate]

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?

like image 657
Phrixus Avatar asked Apr 15 '10 09:04

Phrixus


1 Answers

>>> 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)]
like image 174
YOU Avatar answered Oct 06 '22 08:10

YOU