私はfindUniqueWords
の結果がソートされたことを確認できましたlist
。しかし、それはreturn
list
、なぜですか?なぜ "return list.sort()"がリストを返さないのですか?
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
I thをしていませんインクを使用すると、アイテムを何度も文字列に変換する必要があります。通常は一度は十分ですし、cleanUpの入力でもそれを行うのがよりクリーンです。 – Ben
ちょっとばかげた考えですが、ユニークなアイテムのリストが必要な場合は、セットに変換してみませんか?必要に応じてリストに戻すことができます。 'theSet =セット(theList)' そして、あなたが行われているが、あなただけ戻っリストにキャストする必要があります。 'theList =リスト(theSet)完了' 。簡単です。 – runlevel0