首先,从网上一位好心网友处下载一个正序英语单词列表的txt:
链接:https://pan.baidu.com/s/11FThsKjsAdK3DixmGzgHWQ
提取码:xhik
其次,把这个txt的文件名改成words.txt
,在同一个目录下创建一个.py
文件,把以下代码复制进去并运行,按照提示进行操作即可。
import numpy as np
def have(word, lst):
for c in lst:
if not(c in word):
return False
return True
def donthave(word, lst):
for c in lst:
if c in word:
return False
return True
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
f = open("words.txt")
line = f.readline()
data_list = []
while line:
data_list.append(line[:-1])
line = f.readline()
f.close()
data_array = np.array(data_list)
h_str = input("请按空格输入已知存在的字母(小写):")
h = h_str.split(" ")
dh_str = input("请按空格输入已知不存在的字母(小写):")
dh = dh_str.split(" ")
correct = []
for word in data_array:
if len(word) == 0:
continue
if word[0].isupper():
continue
if len(word) == 5:
if have(word, h):
if donthave(word, dh):
correct.append(word)
b = 'yes'
known = dict()
while 'y' in b:
b = input("是否存在已知位置的字母?(yes/no):")
if 'y' in b:
index = int(input("请输入第几位数是已知的:"))
char = input("请输入该字母:")
known[index] = char
print("以下是符合条件的单词:")
for word in correct:
s = True
for key, value in known.items():
if word[key - 1] != value:
s = False
break
if s:
print(word)
s = input('使用任意输入以关闭窗口')