Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'skip:p 60': 0.05; 'default,': 0.07; 'terry': 0.07; 'doc,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'output': 0.11; '>>>': 0.12; 'examples': 0.12; 'am,': 0.14; 'wrote:': 0.14; '"class': 0.16; '36,': 0.16; 'class:': 0.16; 'dummy': 0.16; 'reedy': 0.16; 'input': 0.17; 'jan': 0.20; 'help.': 0.20; 'header:In-Reply-To:1': 0.21; 'posting': 0.21; 'wrong?': 0.23; 'code': 0.24; 'posted': 0.25; 'match': 0.26; 'example': 0.27; 'problem': 0.28; 'header:X -Complaints-To:1': 0.32; 'to:addr:python-list': 0.33; 'shows': 0.34; 'there': 0.35; 'header:User-Agent:1': 0.35; 'several': 0.36; 'received:org': 0.38; 'subject:from': 0.38; 'subject:: ': 0.38; 'doing': 0.39; 'skip:s 20': 0.39; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'really': 0.40; 'easily': 0.60; 'results': 0.60; 'simply': 0.60; 'future,': 0.76; 'fall.': 0.84; 'stupid': 0.84; 'subject:skip:S 10': 0.91; 'subject:Don': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Don't understand SequenceMatcher from difflib Date: Tue, 21 Jun 2011 15:02:57 -0400 References: <20110621134305.GA8929@trout.vub.ac.be> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: rain.gmane.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10 In-Reply-To: <20110621134305.GA8929@trout.vub.ac.be> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 32 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1308682993 news.xs4all.nl 49047 [::ffff:82.94.164.166]:35022 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:8114 On 6/21/2011 9:43 AM, Antoon Pardon wrote: > matcher = SequenceMatcher(ls1, ls2) ... > What am I doing wrong? Read the doc, in particular, the really stupid signature of the class: "class difflib.SequenceMatcher(isjunk=None, a='', b='', autojunk=True)" You are passing isjunk = ls1, a = ls2, and by default, b=''. So there are no matches, len(a) = 36, len(b) = 0, and the dummy match is (36,0,0) as you got. There are also several example in the doc, all like >>> s = SequenceMatcher(None, " abcd", "abcd abcd") # or >>> s = SequenceMatcher(lambda x: x==" ", " abcd", "abcd abcd") So you will get better results with matcher = SequenceMatcher(None, ls1, ls2) # or matcher = SequenceMatcher(a=ls1, b=ls2) In the future, please try to simply examples before posting for help. print(list(SequenceMatcher('a','abc').get_matching_blocks())) shows the problem you posted in one easily read line of input and output. I only waded through the distracting code and output you posted to find that problem because I patched SequenceMatcher last fall. -- Terry Jan Reedy