I have a string.
s = '1989, 1990'
I want to convert that to list using python & i want output as,
s = ['1989', '1990']
Is there any fastest one liner way for the same?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use the split method:
But you might want to:
remove spaces using replace
split by ‘,’
As such:
This will work better if your string comes from user input, as the user may forget to hit space after a comma.