Remove additional quotes from python list

后端 未结 2 543
一个人的身影
一个人的身影 2021-01-29 06:55

I have a list with below pattern and i want to get rid of \" which is present at the beginning and end of each sub list. I tried replace, strip but they are not the

2条回答
  •  甜味超标
    2021-01-29 07:34

    You can use shlex.split after removing commas with replace:

    import shlex
    
    lst = [["'123', 'Name1', 'Status1'"], ["'234', 'Name2', 'Status2'"]]
    r = [shlex.split(x[0].replace(',', '')) for x in lst]
    # [['123', 'Name1', 'Status1'], ['234', 'Name2', 'Status2']]
    

提交回复
热议问题