Flexable Collating (feedback please)
georgeryoung at gmail.com
georgeryoung at gmail.com
Wed Oct 18 07:48:28 EDT 2006
On Oct 18, 2:42 am, Ron Adam <r... at ronadam.com> 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
More information about the Python-list
mailing list