我已经能够验证 findUniqueWords
确实导致排序 list
。但是,它不会返回列表。为什么?
def findUniqueWords(theList):
newList = []
words = []
# Read a line at a time
for item in theList:
# Remove any punctuation from the line
cleaned = cleanUp(item)
# Split the line into separate words
words = cleaned.split()
# Evaluate each word
for word in words:
# Count each unique word
if word not in newList:
newList.append(word)
answer = newList.sort()
return answer
原文由 Lee_Str 发布,翻译遵循 CC BY-SA 4.0 许可协议
list.sort
对列表进行就地排序,即它不返回新列表。写吧