[Tutor] Location of found item in list.
pyro9219 at gmail.com
Thu Oct 19 04:17:18 CEST 2006
I think this is overkill for what I'm trying to do, could you please refer
to what I just wrote luke? That might make things simpler..
On 10/18/06, John Fouhy <john at fouhy.net> wrote:
> Ok, so your question is:
> If nothing in directoryList matches item, how do I find the
> element of directoryList that should have matched?
> This is a bit tricky, because you need to define exactly what results
> you expect.
> (for example, suppose limitedLineList contained 'SL_39.sdr' and
> directoryList had 'SL39.sdr'. Is that something that should be a
> Possibly you could do this:
> def match(item, lst):
> """ See if item is present in lst.
> output :: bool
> return item in lst
> def near_match(item, lst):
> """ See if item is similar to something in lst. Currently, we just
> match case-insensitive.
> output :: first matching element of lst, or None
> for item2 in lst:
> if item.upper() == item2.upper():
> return item2
> return None
> for item in limitedLineList:
> if match(item, directoryList):
> print '%20s%20s%20s' % ('Match!', item, item)
> item2 = near_match(item, directoryList)
> if item2:
> print '%20s%20s%20s' % ('Fail!', item, item2)
> print '%20s%20s%20s' % ('Fail!', item, '????')
> You can modify near_match if you have some other definition of what
> you want it to return.
> Tutor maillist - Tutor at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor