其它
将文档中的所有的单词逆序并保存,注意是将单词的字母逆序,原单词顺序不变。例如 They are students. 变为yehT era stneduts.
import re
txt = ''
# 读取文件t2内容
with open('t2.txt', 'r') as f:
txt = f.read()
# 提取文件t2内容的单词并做
txt=re.findall('[A-Za-z.]+\.?',txt)
txt1=[]
for i in txt:
# 每个单词做反向后按顺序存入txt1
txt1.append(i[::-1])
# 将txt1存储t3.txt
with open('t3.txt','w+') as f:
f.write(' '.join(txt1))