d = {}
k = []
v = []
with open('dir','r',encoding='utf-8') as f:
for i in f.readlines():
j = i.strip('\n') # 删除换行符
li_k = j.split(',') # 以逗号分隔为列表
d[li_k[0]] = li_k[1]
k.append(li_k[0])
v.append(li_k[1])
print(k)
print(v)
sk = input('请输入要查找的词句:')
sv = []
while len(sk)>0:
m=0
n=0
for i in range(len(sk)+1):
if sk[:i] in k:
sv.append(sk[:i])
sk=sk[i:]
n = 1
m = i
if n==0:
# print(sk)
sv.append(sk[0:1])
sk = sk[m+1:]
# print(sk)
# print(sv)
# print(sv)
get_v = []
for i in sv:
if i in k:
get_v.append(d[i])
else:
get_v.append(i)
re_w = ('_').join(get_v)
print(re_w)