gpt4 book ai didi

python - 替换字典python列表中的文本

转载 作者:太空宇宙 更新时间:2023-11-04 08:09:27 26 4
gpt4 key购买 nike

我正在尝试转换

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

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

有没有办法不用大量拆分和创建字典然后放入列表中?

最佳答案

您可以将其解析为 JSON 字符串。

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

输出-

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

关于python - 替换字典python列表中的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25391657/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com