如何从 Python 中的字符串创建一个没有子列表的列表
How to make one list without a sublist from a string in Python
我正在尝试从 Python 中带有白色 space 的字符串创建一个没有任何子列表的列表?例如:
s = "Hello world"
L = s.split()
print L
>>>> ["H","e","l","l","o"," ","w","o","r","l","d"]
我想避免的是:
s = "Hello world"
L = s.split()
print L
>>>> ["Hello", "world"]
谢谢!
只是 list(s)
将 return 字符串 s
中的字符列表。
>>> s = "Hello world"
>>> list(s)
['H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']
>>>
我正在尝试从 Python 中带有白色 space 的字符串创建一个没有任何子列表的列表?例如:
s = "Hello world"
L = s.split()
print L
>>>> ["H","e","l","l","o"," ","w","o","r","l","d"]
我想避免的是:
s = "Hello world"
L = s.split()
print L
>>>> ["Hello", "world"]
谢谢!
只是 list(s)
将 return 字符串 s
中的字符列表。
>>> s = "Hello world"
>>> list(s)
['H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']
>>>