我已经能够验证findUniqueWords结果是否为sorted 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
theSet= set(theList) 至此,您只需要将其投射回列表即可: theList = list(theSet) 完成。简单。
theSet' into a sorted list with sorted(theSet)`。