[英]Remove prefix quotes from a list of strings
So I have a list that includes some prefix single quotes that I really don't need.所以我有一个列表,其中包含一些我真的不需要的前缀单引号。
I tried to convert them with map().我试图用 map() 转换它们。
The list looks like this:该列表如下所示:
['{"id":"browser","top":5000}', '{"id":"amo_ef_id","top":5000}']
I want it to look like this:我希望它看起来像这样:
[{"id":"browser","top":5000}, {"id":"amo_ef_id","top":5000}]
You could use ast.literal_eval
to safely parse the strings in the list:您可以使用
ast.literal_eval
安全地解析列表中的字符串:
from ast import literal_eval
list(map(literal_eval, my_list))
# [{'id': 'browser', 'top': 5000}, {'id': 'amo_ef_id', 'top': 5000}]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.