我是python的新手,並且有一個簡單的疑問。Python列表理解(將句子轉換爲文字)
我在嘗試列表理解。
我想從字符串中添加單詞到列表中。但無法這樣做。我究竟做錯了什麼?
sentence = "there is nothing much in this"
wordList = sentence.split(" ") #normal in built function
print wordList
wordList = [ x for x in sentence if x!=" "] #using list comprehension
print wordList
'sentence.split(」「)'已經爲您提供了單詞的列表,所以我不知道是否有這裏有任何問題。 –
我想了解清單compreshion。我試圖做同樣的事情。 – abc