如何从给定的字母中找出可能的单词?
你好,
我正在python上写一个"拼字代码"。从给定的字母中获取可能的单词,我有一些问题。例如:
给定字母为:'c','r','n','*'
这里'*'可以是任何字母。
可能的词:"哭泣","玉米","运行"等。
proper_word_list
是包含所有英语单词的文件。
score_of_word
是计算单词分数的函数。
手
是给玩家的字母
以下是我的代码(只能在没有星星的情况下获得可能的单词):
选择 | 换行 | 行号
- def get_possible_words(hand, proper_word_list, score_of_a_letter_list) :
- possible_words = []
- for j in range(len(proper_word_list)):
- k = list(proper_word_list[j])
- k.sort()
- c = "".join(k)
- d = list(hand)
- d.sort()
- m = "".join(d)
- if c in m:
- l = (score_of_word(c, score_of_a_letter_list), proper_word_list[j])
- possible_words.append(l)
- possible_words.sort()
- possible_words.reverse()
- return possible_words
先感谢您。