日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

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

發布時間:2023/12/15 python 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 列表比较不同_python实现比较两段文本不同之处的方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本文實例講述了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,

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

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

本文地址: http://www.cppcns.com/jiaoben/python/125614.html

總結

以上是生活随笔為你收集整理的python 列表比较不同_python实现比较两段文本不同之处的方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。