def wordlist(data,info) :
n = len (data)
for i in range(n):
data[i].append(-1) #data[i]追加一个元素-1
for i in range(n):
d = data[i][0]
if info[k] == -1:
info[k] = i
else:
head = info[k]
q = head
while :
p = q
q = data[q][2]
if q != head:
data[p][2] = i
data[i][2] = q
else:
data[i][2] = head
return data,info
def searchword(data,info,key) :
k = ord(key [0]) - ord("a")
head = info[k]
p = head
while p != -1:
if data[p][0] == key:
return
p = data[p][2]
return "没有找到该单词"
读取词汇数据库,存入列表 data 中,列表的每个元素包含 2 个数据项,分别为英文单词和中 文翻译,如 data = [[‘audio ’,‘音频 ’], [‘binary ’,‘二进制数 ’] …], 数据读取 存入的代码略。
'''
info = [-1] * 26
data,info = wordlist(data,info)
key = input("请输入查找单词:").lower () #转化为小写字母
res = searchword(data,info,key)
print(key, "查找结果是:", res)