[Tutor] Sorting tuples

Mike Nickey mnickey at gmail.com
Thu Jun 21 01:05:02 CEST 2012


Hey all,

I'm working through the google classes to increase my python
understanding and I'm stuck on sorting tuples.
What is being asked is to sort tuples based on the second element of
the tuple in ascending order.

Given a list of non-empty tuples, return a list sorted in increasing
order by the last element in each tuple.
e.g. [(1, 7), (1, 3), (3, 4, 5), (2, 2)] yields [(2, 2), (1, 3), (3,
4, 5), (1, 7)]

What I have is
def sort_last(tuples):
    # +++your code here+++
    print sorted(tuples, key=lamda tuples: tuples[-1])
    return

I'm stuck and don't really understand what lamda is. From various
web-boards I have seen that sorting on -1 should give me the last
element o each sub-list.  Can anyone assist?

-- 
~MEN


More information about the Tutor mailing list