python将每个单词按空格分开并保存到文件中
核心代码
# -*- coding: utf-8 -*- ''' python读取英文文件,将每个单词按照空格分开,并将每个单词独自放一行 ''' def dcfenhang(infile,outfile): infopen = open(infile,'r',encoding='utf-8') outopen = open(outfile,'w',encoding='utf-8') lines = infopen.readlines() for line in lines: for db in line.split(): if db not in outfile: outopen.write(db+'\n') infopen.close() outopen.close() dcfenhang("jb51.txt","fenci.txt")
jb51.txt文件
welcome to visit jb51.net
Thans very much
效果如下图所示
相关推荐
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
夜斗不是神 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20
weiiron 2020-11-16