Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #8190

Re: Don't understand SequenceMatcher from difflib

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <apardon@vub.ac.be>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'responding': 0.04; 'parameter': 0.05; 'received:134': 0.05; 'default,': 0.07; 'terry': 0.07; '21,': 0.09; 'argument,': 0.09; 'assumed': 0.09; 'doc,': 0.09; 'none.': 0.09; '>>>': 0.12; 'examples': 0.12; 'am,': 0.14; 'wrote:': 0.14; '"class': 0.16; '36,': 0.16; '>what': 0.16; 'carefully,': 0.16; 'class:': 0.16; 'dummy': 0.16; 'parameters,': 0.16; 'reedy': 0.16; 'question.': 0.16; 'tue,': 0.17; 'help.': 0.20; 'header:In-Reply-To:1': 0.21; 'posting': 0.21; 'dropped': 0.23; 'somehow': 0.23; 'wrong?': 0.23; 'times,': 0.25; 'posted': 0.25; 'function': 0.25; 'match': 0.26; 'example': 0.27; 'seeing': 0.28; 'thanks': 0.28; 'anyway.': 0.29; 'second': 0.30; 'reminded': 0.30; 'it.': 0.31; "didn't": 0.31; 'value.': 0.32; 'to:addr :python-list': 0.33; '...': 0.34; 'question': 0.34; 'there': 0.35; 'header:User-Agent:1': 0.35; 'doc': 0.35; 'considered': 0.36; 'several': 0.36; 'charset:us-ascii': 0.36; 'two': 0.37; 'subject:from': 0.38; 'but': 0.38; 'subject:: ': 0.38; 'doing': 0.39; 'skip:s 20': 0.39; 'should': 0.39; 'got': 0.39; 'to:addr:python.org': 0.39; 'really': 0.40; 'results': 0.60; 'simply': 0.60; 'taking': 0.64; 'here.': 0.69; 'future,': 0.76; 'stupid': 0.84; 'subject:skip:S 10': 0.91; 'subject:Don': 0.93
X-IronPort-Anti-Spam-Filtered true
X-IronPort-Anti-Spam-Result AmAIAC+MAU6GuA9G/2dsb2JhbABUmDaOWHeIc78Shi0EkWqEV4s3
Date Wed, 22 Jun 2011 09:27:44 +0200
From Antoon Pardon <Antoon.Pardon@rece.vub.ac.be>
To python-list@python.org
Subject Re: Don't understand SequenceMatcher from difflib
References <20110621134305.GA8929@trout.vub.ac.be> <itqpt1$fdk$1@dough.gmane.org>
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Disposition inline
In-Reply-To <itqpt1$fdk$1@dough.gmane.org>
User-Agent Mutt/1.5.20 (2009-06-14)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.274.1308727679.1164.python-list@python.org> (permalink)
Lines 45
NNTP-Posting-Host 82.94.164.166
X-Trace 1308727679 news.xs4all.nl 49047 [::ffff:82.94.164.166]:32889
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:8190

Show key headers only | View raw


On Tue, Jun 21, 2011 at 03:02:57PM -0400, Terry Reedy wrote:
> 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.

Yes my penny dropped an hour after I send the question.

But reading the doc in itself didn't help. I head read and reread it
a number of times, before I finaly posted the question.

Somehow this signature reminded me of the range function where if you
only provide one argument, this is considered to be the second parameter
with the first parameter taking on a default value. So somehow I assumed
that if you only provided two parameters, these would be shifted as in
range and the first parameter would default to None.

I know if you read the documentation carefully, it contradicts this, but
my assumption blinded me for seeing it.

> 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.

Yes my bad here. I should have prepared the question better. Frustration
got the better of me.

Thanks for responding anyway.

-- 
Antoon Pardon

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Don't understand SequenceMatcher from difflib Antoon Pardon <Antoon.Pardon@rece.vub.ac.be> - 2011-06-22 09:27 +0200

csiph-web