On Tue, Mar 11, 2014 at 9:13 AM, Josh English <joshua.r.engl...@gmail.com>wrote:
> print list(sorted(all_the_stuff, key=lambda x: x.name.lower)) > In this case, the key being sorted on is the function object x.name.lower, not the result of the call. It might make more sense if you break the lambda out into a separate def statement, like this: def myKeyFunc(x): return x.name.lower # Return the function that produces the lower-cased name. print list(sorted(all_the_stuff, key=myKeyFunc)) > print list(sorted(all_the_stuff, key=lambda x: x.name.lower())) > In this case, you are calling x.name.lower, and the key being used is the result of that call. And heres what this one looks like broken down: def myKeyFunc(x): return x.name.lower() # Return the lower-cased name. print list(sorted(all_the_stuff, key=myKeyFunc)) Chris
-- https://mail.python.org/mailman/listinfo/python-list