確定構成一個詞實際上是一個相當棘手的問題,但如果你只是指那些有空間之間,那並不難。
list = []
x = raw_input("Text: ")
x.split()
abc = x.split(" ") # print out or otherwise view `abc` --
list.append(abc) # I'm not sure what you want to accomplish here -- this
# puts your list `abc` in your list `list`.
print list.count(",") # I'm not sure why you think `list` would have "," in it
# list has only one thing in it -- another list (abc)
也許這將有助於看一個例子。
>>> list = [] # DON'T CALL IT 'list', give it a different name
>>> x = raw_input("Text: ")
Text: Now is the time for all good men to come to the aid of their country.
>>> x
'Now is the time for all good men to come to the aid of their country.'
>>> abc = x.split()
>>> abc
['Now', 'is', 'the', 'time', 'for', 'all', 'good', 'men', 'to', 'come', 'to', 'the', 'aid', 'of', 'their', 'country.']
>>> list.append(abc)
>>> list
[['Now', 'is', 'the', 'time', 'for', 'all', 'good', 'men', 'to', 'come', 'to', 'the', 'aid', 'of', 'their', 'country.']]
>>> list[0]
['Now', 'is', 'the', 'time', 'for', 'all', 'good', 'men', 'to', 'come', 'to', 'the', 'aid', 'of', 'their', 'country.']
>>> list[0][0]
'Now'
會不會'x.count(」「)+ 1'幫助?或'len(x.split())'選項卡和換行符。 – WKPlus
爲什麼不只是'len(abc)'? – mhlester
'list'是a)一個不好的名字(它影響了一個內建的名字,它不是描述性的),b)對你沒有任何幫助。 –