[Tutor] 'Last' in Python?
Dave Friedman
outta.names at gmail.com
Mon Mar 11 01:16:17 CET 2013
Hi all,
I'm teaching myself Python in part with Google's course, and one of the
exercises is to sort a list of tuples by the last element.
e.g.: a list [(1, 7), (1, 3), (3, 4, 5), (2, 2)] yields [(2, 2), (1, 3),
(3, 4, 5), (1, 7)].
My answer, after figuring out lambda functions, is
def sort_last(tuples):
return sorted(tuples, key= lambda t: t[-1])
Google's answer is much more straightforward, except for one part.
def sort_last(tuples)
return sorted(tuples, key=last)
What is 'last', and where can I find a description of it? Searching the web
and the python docs hasn't been helpful. (Maybe I'm searching badly?)
Insight and pointers appreciated.
Thanks,
-Dave
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130310/686d8002/attachment-0001.html>
More information about the Tutor
mailing list