内容简介:这篇文章主要介绍了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
效果如下图所示
这篇文章就介绍到这了,希望大家以后多多支持Codercto.com。
以上所述就是小编给大家介绍的《python将每个单词按空格分开并保存到文件中》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- 算法 – 给出一个单词,打印其索引,可以相应地增加单词
- C++ 中的替换空格
- Elasticsearch的wildcard空格问题
- xml中的空格之完全解说
- Pocketsphinx – 添加单词和提高准确性
- ios – 用Objective-C替换空格
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
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》 这本书的介绍吧!