string to list conversion in python

后端 未结 6 2247
借酒劲吻你
借酒劲吻你 2021-01-13 05:25

I have a string.

s = \'1989, 1990\'

I want to convert that to list using python & i want output as,

s = [\'1989\', \'19         


        
6条回答
  •  感动是毒
    2021-01-13 05:45

    Use list comprehensions:

    s = '1989, 1990'
    [x.strip() for x in s.split(',')]
    

    Short and easy.

    Additionally, this has been asked many times!

提交回复
热议问题