将字符串转换为 python 中的列表的最佳方法是什么
what is the best way to convert string to list in python
在 python
中将字符串转换为列表的最佳方法是什么
一般来说,
someString = "Stack Overflow"
someList = list(someString.split(" "))
print(someList) # This shows ['Stack', 'Overflow']
处理空格的更好方法,
someString = " Stack Overflow "
someList = list(" ".join(someString.split()).split(" "))
print(someList) # This shows ['Stack', 'Overflow'] instead of ['', 'Stack', '', '', '', '', '', '', '', 'Overflow']
在 python
中将字符串转换为列表的最佳方法是什么一般来说,
someString = "Stack Overflow"
someList = list(someString.split(" "))
print(someList) # This shows ['Stack', 'Overflow']
处理空格的更好方法,
someString = " Stack Overflow "
someList = list(" ".join(someString.split()).split(" "))
print(someList) # This shows ['Stack', 'Overflow'] instead of ['', 'Stack', '', '', '', '', '', '', '', 'Overflow']