On Fri, Feb 11, 2011 at 4:06 PM, kyleduncan <[email protected]> wrote:
> I dont understand what the x is, but thank you so much for fixing this
> for me in a matter of minutes!
>


You're welcome.

The 'key' kwarg to the sort function expects a value. Instead of
giving it a single value, you can pass a function.

So, you could have done this:

def return_last_login(record):

    return record.user.last_login

Then: my_list.sort(key = return_last_login(x))

But you can use a shortcut and use the 'lambda' keyword, which just
returns an anonymous function.

So, these two are equivalent:

    my_function = return_last_login

    my_function = lambda x: x.user.last_login

I hope this helps.

Shawn

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to