Remove prefix quotes from a list of strings

前端 未结 1 1492
礼貌的吻别
礼貌的吻别 2021-01-25 07:51

So I have a list that includes some prefix single quotes that I really don\'t need.

I tried to convert them with map().

The list looks like this:



        
相关标签:
1条回答
  • 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}]
    
    0 讨论(0)
提交回复
热议问题