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

栏目: 编程语言 · Python · 发布时间: 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将每个单词按空格分开并保存到文件中

这篇文章就介绍到这了,希望大家以后多多支持Codercto.com。


以上所述就是小编给大家介绍的《python将每个单词按空格分开并保存到文件中》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Intersectional Internet

The Intersectional Internet

Safiya Umoja Noble、Brendesha M. Tynes / Peter Lang Publishing / 2016

From race, sex, class, and culture, the multidisciplinary field of Internet studies needs theoretical and methodological approaches that allow us to question the organization of social relations that ......一起来看看 《The Intersectional Internet》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

随机密码生成器
随机密码生成器

多种字符组合密码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试