• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > python实现比较两段文本不同之处的方法

python实现比较两段文本不同之处的方法

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python实现文本分类,python文本编辑器,python文本分类,python文本挖掘,python 文本处理等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例讲述了python实现比较两段文本不同之处的方法。分享给大家供大家参考。具体实现方法如下:

# find the difference between two texts
# tested with Python24  vegaseat 6/2/2005
import difflib
text1 = """The World's Shortest Books:
Human Rights Advances in China
"My Plan to Find the Real Killers" by OJ Simpson
"Strom Thurmond: Intelligent Quotes"
America's Most Popular Lawyers
Career Opportunities for History Majors
Different Ways to Spell "Bob"
Dr. Kevorkian's Collection of Motivational Speeches
Spotted Owl Recipes by the EPA
The Engineer's Guide to Fashion
Ralph Nader's List of Pleasures
"""
text2 = """The World's Shortest Books:
Human Rights Advances in China
"My Plan to Find the Real Killers" by OJ Simpson
"Strom Thurmond: Intelligent Quotes"
America's Most Popular Lawyers
Career Opportunities for History Majors
Different Ways to Sell "Bob"
Dr. Kevorkian's Collection of Motivational Speeches
Spotted Owl Recipes by the EPA
The Engineer's Guide to Passion
Ralph Nader's List of Pleasures
"""
# create a list of lines in text1
text1Lines = text1.splitlines(1)
print "Lines of text1:"
for line in text1Lines:
 print line,
print
# dito for text2
text2Lines = text2.splitlines(1)
print "Lines of text2:"
for line in text2Lines:
 print line,
print 
diffInstance = difflib.Differ()
diffList = list(diffInstance.compare(text1Lines, text2Lines))
print '-'*50
print "Lines different in text1 from text2:"
for line in diffList:
 if line[0] == '-':
  print line,

</div>

希望本文所述对大家的Python程序设计有所帮助。

</div>

您可能想查找下面的文章:

  • Python如何实现文本转语音
  • python实现比较两段文本不同之处的方法
  • python实现将文本转换成语音的方法
  • python实现将文本转换成语音的方法

相关文章

  • python strip()函数 介绍
  • 使用python实现生成用户信息
  • 用实例分析Python中method的参数传递过程
  • github配置使用指南
  • 简单介绍Python的轻便web框架Bottle
  • Python爬取网页中的图片(搜狗图片)详解
  • Python保存MongoDB上的文件到本地的方法
  • 详解Python的Django框架中的Cookie相关处理
  • python实现DES加密解密方法实例详解
  • Python变量和数据类型详解

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Python中for循环和while循环的基本使用方法
    • Python的Bottle框架中返回静态文件和JSON对象的方法
    • 解决python3 urllib中urlopen报错的问题
    • 在RedHat系Linux上部署Python的Celery框架的教程
    • python3.5仿微软计算器程序
    • Python中几个比较常见的名词解释
    • 介绍Python的Django框架中的静态资源管理器django-pipeline
    • ssh批量登录并执行命令的python实现代码
    • Python自定义函数的创建、调用和函数的参数详解
    • Python实现约瑟夫环问题的方法

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有