Convert strings of list to list of integers inside a list

前端 未结 5 1622
长发绾君心
长发绾君心 2021-01-28 20:02

I have a list of strings and those strings are lists. Like this: [\'[1,2,3]\',\'[10,12,5]\'], for example. I want to get a list of lists or even every list there: <

5条回答
  •  旧巷少年郎
    2021-01-28 20:17

    You use ast.literal_eval

    import ast
    l =  ['[1,2,3]','[10,12,5]']
    l = [ast.literal_eval(i) for i in l]
    

提交回复
热议问题