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
ベストアンサー1
list.sort
リストをその場でソートします。つまり、新しいリストを返しません。次のように記述するだけです。
newList.sort()
return newList