【发布时间】:2023-03-24 08:16:01
【问题描述】:
这是我得到的。当我运行它时它不起作用。有人可以帮助指导我的代码有什么问题吗?
def unique_words(text : str) ->list:
text = open(text, 'r')
text_contents = text.read()
text.close()
word_list = text_contents.split()
word = open(str, 'w')
unique = []
for word in word_list:
if word not in word_list:
file.append(str(word) + "\n")
unique.sort()
返回(唯一)
【问题讨论】:
-
如果你要发布 Python 代码,你需要准确地重现你的缩进。否则读者需要猜测哪些问题是你想问的问题,以及你通过弄乱缩进引入了哪些问题。
标签: python python-3.x list python-2.7 computer-science