2
这个算法将输入一个数字,然后返回字典中有多少个字典从.txt
文件中获得该长度。我得到6783的输出,如果我输入5时,我应该根据我的列表获得5046。我不知道还有什么可以改变的。Jumble anagram最长的单词python
例如:5的输入应该回到5046
我也一直在试图通过列表与字长正整数的输入进行搜索,收集单词,字谜的最高金额,我不知道从哪里开始。
例如:用于字长度的4输入应该返回字谜这是6的最大数量,并输出字谜的列表中,例如
[’opts’, ’post’, ’pots’, ’spot’, ’stop’, ’tops’]
def maxword():
input_word = int(input("Enter word length (hit enter key to quit):"))
word_file = open("filename", "r")
word_list = {}
alist = []
for text in word_file:
simple_text = ''.join(sorted(text.strip()))
word_list.update({text.strip(): simple_text})
count = 0
for num in word_list.values():
if len(num) == input_word:
count += 1
alist.append(num)
return str(input_word) + str(len(alist))