나는 findUniqueWords
이 정렬 된 결과임을 확인했습니다. list
. 그러나 return
은 list
이 아니므로 그 이유는 무엇입니까?왜 "return list.sort()"는 목록이 아닌 None을 반환합니까?
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
것은 내가 토륨하지 않습니다 값은 하지deep copy, 그래서 평소와 같이 목록에 포함 된 요소의 측면 effecty 작업에 대한주의입니다 잉크를 사용하면 항목을 여러 번 문자열로 바꿔야합니다. 일단 정상적으로 완료되면 청소를위한 입력에서이를 수행하는 것이 더 깔끔합니다. – Ben
어리석은 생각이지만, 고유 항목 목록을 원한다면 왜 세트로 변환하지 않으시겠습니까? 그런 다음 필요할 경우 목록으로 다시 변환 할 수 있습니다. 'theSet = 세트 (theList)는' 그리고 당신은 완료, 당신은 단지 목록에 다시 캐스팅해야합니다 'theList = 목록 (theSet가)' 가 완료. 쉬운. – runlevel0