I have the string below gotten as the output from another process. I need to get only the list of list within the string out that is by eliminating the following 0.466, 0.161 : 19.032
that are the characters at the end of the string.
The string:
route = '''[[(5371.0, 10558.0, {'volume': 8.627265, 'length': 0.17}), (14604.0, 71071.0, {'volume': 15.135287, 'length': 0.28})], [(68127, 68127.0, {'volume': 10.072853, 'length': 0.25}), (5706, 5706.0, {'volume': 27.82635, 'length': 0.25, })], 0.466, 0.161] : 19.032'''
My desired output is the list of list below
[[(5371.0, 10558.0, {'volume': 8.627265, 'length': 0.17}), (14604.0, 71071.0, {'volume': 15.135287, 'length': 0.28})], [(68127, 68127.0, {'volume': 10.072853, 'length': 0.25}), (5706, 5706.0, {'volume': 27.82635, 'length': 0.25})]]
I tried this:
result = []
for r in eval(route.split(":")[0]):
if type(r) == type([]):
result.append(r)
print result
I got this error:
Traceback (most recent call last):
File "C:/Users/AMAMIFE/Desktop/obi/SO.py", line 419, in <module>
for l in eval(route.split(":")[0]):
File "<string>", line 1
[[(5371.0, 10558.0, {'volume'
^
SyntaxError: unexpected EOF while parsing
Can I get some help with what I am doing wrong and how to fix it?