python

超轻量级php框架startmvc

python将每个单词按空格分开并保存到文件中

更新时间:2020-05-25 07:00:01 作者:startmvc
核心代码#-*-coding:utf-8-*-'''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

效果如下图所示

这篇文章就介绍到这了,希望大家以后多多支持脚本之家。

python 单词 空格分开