user3089927
user3089927

Reputation: 3895

replace text from list of dictionary python

I am trying to convert

list1=["{\"username\":\"abhi\",\"pass\":2087}"]

to

list1=[{"username":"abhi","pass":2087}]

Is there any way to do it without lots of splitting and creating dictionary and then putting into list?

Upvotes: 1

Views: 92

Answers (1)

Shashank Agarwal
Shashank Agarwal

Reputation: 2804

You can parse it as a JSON string.

import json
list2 = [json.loads(item) for item in list1]

Output -

[{u'pass': 2087, u'username': u'abhi'}]

Upvotes: 6

Related Questions