如何在Python中的字符串中创建一个没有子列表的列表

时间:2015-03-08 23:21:57

标签: python jython

我正在尝试创建一个没有任何子列表的列表来自Python中带有空格的字符串?例如:

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"]

谢谢!

1 个答案:

答案 0 :(得分:3)

只需list(s)即可返回字符串s中的字符列表。

>>> s = "Hello world"
>>> list(s)
['H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']
>>>