what is the best way to convert string to list in python
question from:https://stackoverflow.com/questions/65880257/what-is-the-best-way-to-convert-string-to-list-in-pythonwhat is the best way to convert string to list in python
question from:https://stackoverflow.com/questions/65880257/what-is-the-best-way-to-convert-string-to-list-in-pythonGenerally speaking,
someString = "Stack Overflow"
someList = list(someString.split(" "))
print(someList) # This shows ['Stack', 'Overflow']
A better way to handle spaces,
someString = " Stack Overflow "
someList = list(" ".join(someString.split()).split(" "))
print(someList) # This shows ['Stack', 'Overflow'] instead of ['', 'Stack', '', '', '', '', '', '', '', 'Overflow']