此函数旨在将从字典文件导入的所有127,000个单词与输入长度的用户进行比较。然后它应该返回等于该长度的单词量。它确实在一定程度上做到了这一点。Python - 将127,000+个单词导入列表,但函数仅返回部分结果
如果输入“15”,则返回“0”。 如果输入“4”,则返回“3078”。
我确信长度为15个字符的单词不管怎样都返回“0”。 我还要提到的是,如果我输入任何大于15的结果仍然是0时,有更大的话15
try:
dictionary = open("dictionary.txt")
except:
print("Dictionary not found")
exit()
def reduceDict():
first_list = []
for line in dictionary:
line = line.rstrip()
if len(line) == word_length:
for letter in line:
if len([ln for ln in line if line.count(ln) > 1]) == 0:
if first_list.count(line) < 1:
first_list.append(line)
else:
continue
if showTotal == 'y':
print('|| The possible words remaing are: ||\n ',len(first_list))
给出一行dictionary.txt作为示例输入,以便我们可以了解输入的结构 – bigbounty
在字典文件中,每行都有一个单词。即 chemotherapeutic – MLJezus
你还可以详细说明为什么你需要'在线信:' – kuro