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

首頁 > 編程 > Python > 正文

python實現比較兩段文本不同之處的方法

2019-11-25 17:20:55
字體:
來源:轉載
供稿:網友

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

# 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,

希望本文所述對大家的Python程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 定西市| 内黄县| 甘谷县| 岳普湖县| 桐梓县| 富民县| 红桥区| 隆德县| 象山县| 多伦县| 鄂托克前旗| 方正县| 达日县| 金湖县| 安庆市| 邵阳县| 洛隆县| 城固县| 河东区| 班戈县| 加查县| 岱山县| 襄汾县| 烟台市| 张家界市| 石景山区| 临湘市| 彭阳县| 岳普湖县| 镇平县| 延安市| 本溪市| 乐都县| 阜宁县| 锡林郭勒盟| 铜梁县| 沂源县| 泊头市| 洪雅县| 新昌县| 乌鲁木齐县|