words = [‘cat’, ‘window’, ‘defenestrate’]
# for w in words:
# # print(w)
n=-1
for w in words[0:len(words)]:
# n=n+1
# print(n)
# if n < len(words)-1 and :
# print(words[n+1])
# #print(w)
dict = {‘aa’:‘aaaa’,‘bb’:‘bbbb’,‘cc’:‘cccc’,‘dd’:‘dddd’,‘ee’:‘eeee’}
file=“d:\python\2.txt”
#def string_switch(file,y,dict[‘abc’],s=1):
def changefile(file):
with open(file, “r”, encoding=“utf-8”) as f:
#readlines以列表的形式将文件读出
lines = f.readlines()
#print(lines)
global t,b
t = “t”
b=“b”
with open(file, “w”, encoding=“utf-8”) as f_w:
#定义一个数字,用来记录在读取文件时在列表中的位置
#n = 0
#默认选项,只替换第一次匹配到的行中的字符串
#len(list(dict.keys()))
for