国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python實(shí)現(xiàn)比較兩段文本不同之處的方法

2020-02-23 01:29:27
字體:
供稿:網(wǎng)友

本文實(shí)例講述了python實(shí)現(xiàn)比較兩段文本不同之處的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

# find the difference between two texts# tested with Python24  vegaseat 6/2/2005import difflibtext1 = """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 LawyersCareer Opportunities for History MajorsDifferent Ways to Spell "Bob"Dr. Kevorkian's Collection of Motivational SpeechesSpotted Owl Recipes by the EPAThe Engineer's Guide to FashionRalph 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 LawyersCareer Opportunities for History MajorsDifferent Ways to Sell "Bob"Dr. Kevorkian's Collection of Motivational SpeechesSpotted Owl Recipes by the EPAThe Engineer's Guide to PassionRalph Nader's List of Pleasures"""# create a list of lines in text1text1Lines = text1.splitlines(1)print "Lines of text1:"for line in text1Lines: print line,print# dito for text2text2Lines = text2.splitlines(1)print "Lines of text2:"for line in text2Lines: print line,print diffInstance = difflib.Differ()diffList = list(diffInstance.compare(text1Lines, text2Lines))print '-'*50print "Lines different in text1 from text2:"for line in diffList: if line[0] == '-':  print line,

希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 濉溪县| 大城县| 清流县| 华容县| 郧西县| 贡嘎县| 东光县| 朝阳市| 黔江区| 定陶县| 来凤县| 浮山县| 盐津县| 武汉市| 遵化市| 长沙市| 博客| 阳谷县| 莎车县| 井冈山市| 商都县| 祁阳县| 望谟县| 开阳县| 科尔| 弥勒县| 湖南省| 洪江市| 额尔古纳市| 裕民县| 河源市| 兴城市| 普安县| 柳河县| 璧山县| 开远市| 河池市| 武城县| 广德县| 漠河县| 和龙市|