def getUniqueWords(wordsList) :
"""
Returns the subset of unique words containing all of the words that are presented in the
text file and will only contain each word once. This function is case sensitive
"""
uniqueWords = {}
for word in speech :
if word not in speech:
uniqueWords[word] = []
uniqueWords[word].append(word)
假设您正在向
getUniqueWords()
传递一个干净的单词列表,您可以始终返回该列表的set
,由于集合的属性,该列表将删除重复项尝试:
注意:当您键入问题时,您使用的是
markdown
,将代码包含在后面的记号中,这使得灰色框的格式设置很好。单勾号使方框内联like this
,三个背面的勾号(顶部的语言)表示方框编辑:以帮助您评论
您可以执行在列表上调用
set()
的操作,但需要手动执行:这就是在
list
上调用set()
所做的。此外,在开放式问题上不使用内置函数(不指定方法)是对任何问题的愚蠢补充,尤其是在使用python时相关问题 更多 >
编程相关推荐