欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2015年05月30日 12:39:34   作者:不吃皮蛋  
這篇文章主要介紹了python實(shí)現(xiàn)比較兩段文本不同之處的方法,涉及Python針對(duì)文本與字符串的相關(guān)操作技巧,需要的朋友可以參考下

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

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

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

相關(guān)文章

  • Python爬蟲(chóng)實(shí)戰(zhàn)之使用Scrapy爬取豆瓣圖片

    Python爬蟲(chóng)實(shí)戰(zhàn)之使用Scrapy爬取豆瓣圖片

    在用Python的urllib和BeautifulSoup寫(xiě)過(guò)了很多爬蟲(chóng)之后,本人決定嘗試著名的Python爬蟲(chóng)框架——Scrapy.本次分享將詳細(xì)講述如何利用Scrapy來(lái)下載豆瓣名人圖片,需要的朋友可以參考下
    2021-06-06
  • python中的getter與setter你了解嗎

    python中的getter與setter你了解嗎

    這篇文章主要為大家詳細(xì)介紹了python中的getter與setter,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2022-03-03
  • Python實(shí)現(xiàn)操作Redis所有類型的方法詳解

    Python實(shí)現(xiàn)操作Redis所有類型的方法詳解

    Redis作為一款高性能的NoSQL數(shù)據(jù)庫(kù),越來(lái)越受到了廣大開(kāi)發(fā)者的喜愛(ài)。本篇博客將介紹如何使用Python操作Redis的所有類型,以及一些高級(jí)用法,感興趣的可以了解一下
    2023-04-04
  • python中partial()基礎(chǔ)用法說(shuō)明

    python中partial()基礎(chǔ)用法說(shuō)明

    這篇文章主要給大家介紹了關(guān)于python中partial()基礎(chǔ)用法的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用python具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起看看吧
    2018-12-12
  • python偏函數(shù)partial用法

    python偏函數(shù)partial用法

    這篇文章要給大家分享得是python偏函數(shù)partial用法,主要介紹什么是偏函數(shù)partial、偏函數(shù)的作用、偏函數(shù)的語(yǔ)法及案例詳情,需要的朋友可以參考一下文章得具體詳解,希望對(duì)你有所幫助
    2021-10-10
  • python開(kāi)發(fā)之a(chǎn)naconda以及win7下安裝gensim的方法

    python開(kāi)發(fā)之a(chǎn)naconda以及win7下安裝gensim的方法

    這篇文章主要介紹了python開(kāi)發(fā)之a(chǎn)naconda以及win7下安裝gensim的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-07-07
  • python爬取cnvd漏洞庫(kù)信息的實(shí)例

    python爬取cnvd漏洞庫(kù)信息的實(shí)例

    今天小編就為大家分享一篇python爬取cnvd漏洞庫(kù)信息的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-02-02
  • selenium獲取元素定位的方法總結(jié)(動(dòng)態(tài)獲取元素)

    selenium獲取元素定位的方法總結(jié)(動(dòng)態(tài)獲取元素)

    要想操作一個(gè)元素,首先應(yīng)該識(shí)別這個(gè)元素,人有各種的特征(屬性),可以通過(guò)其特征找到人,同理,界面的某個(gè)元素會(huì)有各種的特征(屬性),可以通過(guò)這個(gè)屬性找到這對(duì)象,本文給大家介紹了python?selenium獲取元素定位的8種方法,需要的朋友可以參考下
    2024-02-02
  • python文件操作之批量修改文件后綴名的方法

    python文件操作之批量修改文件后綴名的方法

    這篇文章主要介紹了python文件操作之批量修改文件后綴名,需要的朋友可以參考下
    2018-08-08
  • Python urlopen()函數(shù) 示例分享

    Python urlopen()函數(shù) 示例分享

    urlopen(url, data=None, proxies=None) 即創(chuàng)建一個(gè)表示遠(yuǎn)程url的類文件對(duì)象,然后像本地文件一樣操作這個(gè)類文件對(duì)象來(lái)獲取遠(yuǎn)程數(shù)據(jù)。參數(shù)url表示遠(yuǎn)程數(shù)據(jù)的路徑,一般是網(wǎng)址;參數(shù)data表示以post方式提交到url的數(shù)據(jù);參數(shù)proxies用于設(shè)置代理。
    2014-06-06

最新評(píng)論