Convert string to list in python
Question: I need to convert an string to a list in python, The string format is as
follows,

    
    
    '[{"name":"Tom","adress":"adress1"},{"name":"Mari","adress":"adress2"}]'
    

I need to convert this **string** in to python **list** data type and want to
get the dictionaries by iterating that generated list.

I have tried json library and no luck. > correction (**json.loads is
working**.)

Can you please tell me the correct way to do so ?


Answer: You can `ast.literal_eval` it without any problem.

    
    
    >>> s = '[{"name":"Tom","adress":"adress1"},{"name":"Mari","adress":"adress2"}]'
    >>> import ast
    >>> ast.literal_eval(s)
    [{'adress': 'adress1', 'name': 'Tom'}, {'adress': 'adress2', 'name': 'Mari'}]
    

but `json.loads` doesn't seem to have any problem with it either ...

    
    
    >>> import json
    >>> json.loads(s)
    [{u'adress': u'adress1', u'name': u'Tom'}, {u'adress': u'adress2', u'name': u'Mari'}]
    >>> 
    

