Question on sort() key function
Robert Latest
boblatest at yahoo.com
Tue Jan 22 04:12:19 EST 2008
Paul Rubin wrote:
> The attribute is on instances of File, not on the class itself. See
> if this works:
>
> flist.sort(key=lambda f: f.mod_date.toordinal)
It doesn't throw an error any more, but neither does it sort the list. This,
however, works:
----------------------
def by_date(f1, f2):
return f1.mod_date.toordinal() - f2.mod_date.toordinal()
flist.sort(by_date)
----------------------
So I'm sticking with it, although I sort of liked the key approach.
robert
More information about the Python-list
mailing list