Question on sort() key function
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Tue Jan 22 05:04:54 EST 2008
On Tue, 22 Jan 2008 09:56:55 +0000, Robert Latest wrote:
> Peter Otten wrote:
>> Robert Latest wrote:
>>
>> This should work then:
>>
>> def date_key(f):
>> return f.mod_date.toordinal()
>> flist.sort(key=date_key)
>>
>> This can also be written as
>>
>> flist.sort(key=lambda f: f.mod_date.toordinal())
>
> Well, that's almost Paul's (non-working) suggestion above, but it works
> because of the parentheses after toordinal. Beats me how both versions can
> be valid, anyway.
>
> To me it's all greek. I grew up with C function pointers, and they
> always work.
>
> robert
Suppose `func` is a C function pointer, then
foo = func;
and
foo = func();
have different meanings. It's just the same in Python. First is the
function itself, second *calls* the function.
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list