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))