国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 格尔木市| 长顺县| 长泰县| 临安市| 佳木斯市| 汕头市| 吉林市| 顺义区| 剑川县| 青铜峡市| 郯城县| 莲花县| 大同市| 吉安县| 乌恰县| 泸西县| 雷州市| 登封市| 湖南省| 古丈县| 富裕县| 子长县| 崇文区| 云龙县| 凉城县| 富源县| 象山县| 嘉禾县| 沅江市| 永善县| 安岳县| 夹江县| 永福县| 石门县| 来安县| 库车县| 宿迁市| 益阳市| 东乡族自治县| 玉环县| 宜阳县|