python将每个单词按空格分开并保存到文件中
作者:为援不可图 时间:2023-07-01 12:46:31
核心代码
# -*- 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
效果如下图所示
来源:http://blog.csdn.net/qq_32113189/article/details/79591347
标签:python,单词,空格分开
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
go Antlr重构脚本解释器实现示例
2024-04-26 17:19:44
![](https://img.aspxhome.com/file/2023/8/134258_0s.png)
Tensorflow2.4从头训练Word Embedding实现文本分类
2023-05-22 20:03:17
Python字符串的创建和驻留机制详解
2022-07-07 18:49:17
![](https://img.aspxhome.com/file/2023/3/99193_0s.png)
在数据库里将毫秒转换成date格式的方法
2024-01-19 01:27:00
Python之random库的常用函数有哪些
2022-10-04 03:01:13
![](https://img.aspxhome.com/file/2023/8/83838_0s.png)
浅谈django 重载str 方法
2022-12-17 18:40:33
![](https://img.aspxhome.com/file/2023/8/114538_0s.jpg)
Python图像运算之图像阈值化处理详解
2023-03-20 22:36:24
![](https://img.aspxhome.com/file/2023/5/85205_0s.png)
python实现LRU热点缓存及原理
2022-01-08 01:26:15
Python面向对象编程之类的概念
2021-12-24 10:56:33
python使用pgzero进行游戏开发
2022-10-28 11:32:35
![](https://img.aspxhome.com/file/2023/1/71981_0s.png)
如何对Mysql 数据表压缩
2010-11-25 17:21:00
Golang学习笔记之延迟函数(defer)的使用小结
2024-02-03 07:56:04
浅谈javascript中的DOM方法
2024-04-29 13:44:12
asp获取完整url地址代码
2010-03-22 14:25:00
python导出chrome书签到markdown文件的实例代码
2022-08-26 00:49:36
PHP获取指定日期是星期几的实现方法
2024-05-09 14:47:21
python中的Pytorch建模流程汇总
2022-04-26 19:02:14
vue脚手架vue-cli的卸载与安装方式
2023-07-02 17:04:25
![](https://img.aspxhome.com/file/2023/8/139918_0s.png)
php事务处理实例详解
2024-05-13 09:25:30
行转列之SQL SERVER PIVOT与用法详解
2024-01-28 10:41:37