[英]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? 有什么方法可以做到,无需大量拆分和创建字典,然后放入列表?
You can parse it as a JSON string. 您可以将其解析为JSON字符串。
import json
list2 = [json.loads(item) for item in list1]
Output - 输出-
[{u'pass': 2087, u'username': u'abhi'}]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.