【发布时间】:2015-07-05 07:50:51
【问题描述】:
我正在尝试从两个输入文件中查找所有匹配的单词,但我不断收到“TypeError: unhashable type: 'list'”。我不知道为什么。有人可以告诉我我做错了什么以及如何解决它
#!/usr/bin/python3
#First file
file = raw_input("Please enter the name of the first file: ")
store = open(file)
new = store.read()
#Second file
file2 = raw_input("Please enter the name of the second file: ")
store2 = open(file2)
new = store2.read()
words = set(line.strip() for line in new)
for line in new:
word2 = line.split()
if word2 in words:
print words
【问题讨论】:
标签: python input split store words