Nested lists/Dictionary strings conversion

Hi,

i`ve got a nested list and a nested dictionary as a string...
i want to convert them into a nested list and a dictionary ..how do i go about doing that...
something like ['sdaf','asdf','sasfs',['sdfsd','asdfs','sadfs']]
and  ['sdfsd','sadfsd','sadfsaf,{'asdfas':'sdfasfsa','safasd':'asfsad',['sadfs','sadfasf']:['asdfsd','asdf']}]
I get the strings from a file..i`m trying to analyse some logs here and these things are printed in the logs...
Any python code wud be of great help....

Atul
atulkamatAsked:
Who is Participating?
 
mish33Commented:
Use eval.

>>> eval("['sdaf','asdf','sasfs',['sdfsd','asdfs','sadfs']]")
eval("['sdaf','asdf','sasfs',['sdfsd','asdfs','sadfs']]")

>>> eval("['sdfsd','sadfsd','sadfsaf',{'asdfas':'sdfasfsa','safasd':'asfsad',['sadfs','sadfasf']:['asdfsd','asdf']}]")
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
  File "<string>", line 0, in ?
TypeError: list objects are unhashable
>>> 
You can't have a list as a dictionary key.

>>> eval("['sdfsd','sadfsd','sadfsaf',{'asdfas':'sdfasfsa','safasd':'asfsad',('sadfs','sadfasf'):['asdfsd','asdf']}]")
['sdfsd', 'sadfsd', 'sadfsaf', {'asdfas': 'sdfasfsa', ('sadfs', 'sadfasf'): ['asdfsd', 'asdf'], 'safasd': 'asfsad'}]

And catch SyntaxError as well, because use skipped closing quote in second example after sadfsaf.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.