मैं यह सत्यापित करने में सक्षम हूं कि 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
theSet= set(theList) और आप कर रहे हैं, आपको इसे केवल सूची में वापस लाने की आवश्यकता है: हो theList = list(theSet) गया। आसान।
theSet' into a sorted list with सॉर्ट (सेट) को परिवर्तित कर सकते हैं ।