从字符串列表中删除前缀引号 [英] 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.
我尝试使用map()进行转换。
I tried to convert them with map().
列表如下:
['{"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}]
推荐答案
您可以使用 ast.literal_eval
以安全地解析列表中的字符串:
You could use ast.literal_eval
to safely parse the strings in the list:
from ast import literal_eval
list(map(literal_eval, my_list))
# [{'id': 'browser', 'top': 5000}, {'id': 'amo_ef_id', 'top': 5000}]
这篇关于从字符串列表中删除前缀引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文