Re: Flexable Collating (feedback please)
- From: Ron Adam <rrr@xxxxxxxxxxx>
- Date: Wed, 18 Oct 2006 09:35:58 -0500
georgeryoung@xxxxxxxxx wrote:
On Oct 18, 2:42 am, Ron Adam <r...@xxxxxxxxxxx> wrote:I put together the following module today and would like some feedback on any,,,
obvious problems. Or even opinions of weather or not it is a good approach.
def __call__(self, a, b):
""" This allows the Collate class work as a sort key.
USE: list.sort(key=Collate(flags))
"""
return cmp(self.transform(a), self.transform(b))
You document _call__ as useful for the "key" keyword to sort, but you
implement it for the "cmp" keyword. The "key" allows much better
performance, since it's called only once per value. Maybe just :
return self.transform(a)
-- George
Thanks, I changed it to the following...
def __call__(self, a):
""" This allows the Collate class work as a sort key.
USE: list.sort(key=Collate(flags))
"""
return self.transform(a)
And also changed the sort call here ...
def collate(slist, flags=0):
""" Collate list of strings in place.
"""
slist.sort(key=Collate(flags)) <<<
Today I'll do some performance tests to see how much faster it is for moderate sized lists.
Cheers,
Ron
.
- References:
- Flexable Collating (feedback please)
- From: Ron Adam
- Re: Flexable Collating (feedback please)
- From: georgeryoung
- Flexable Collating (feedback please)
- Prev by Date: Re: Save/Store whole class (or another object) in a file
- Next by Date: Re: Python RPM package arch compatability
- Previous by thread: Re: Flexable Collating (feedback please)
- Next by thread: Re: Flexible Collating (feedback please)
- Index(es):