[EMAIL PROTECTED] wrote:
>
> On Oct 18, 2:42 am, Ron Adam <[EMAIL PROTECTED]> 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
--
http://mail.python.org/mailman/listinfo/python-list