【发布时间】:2021-03-28 00:04:33
【问题描述】:
所以我制作了一个拼字游戏程序,在给定字符输入的情况下,它会打印所有可能的单词,但是它会打印无法生成的单词,例如运行输入时的 nun。有人可以帮我吗?我不知道如何解决这个问题。这是代码。
from itertools import product
from english_words import english_words_set
a = input()
x = True
li = list(a)
for comb in product(li, repeat=len(li)):
b = ''.join(comb)
if b in english_words_set:
i = 0
while i < len(li):
if not li[i] in b:
x = False
i += 1
if li[i] in b:
x = True
i += 1
if x == True:
print(b)```
【问题讨论】:
标签: python string combinations