On Mon, Jun 23, 2008 at 8:09 PM, Dick Moores <[EMAIL PROTECTED]> wrote:

> def sort_tuple_list_by_2nd_elements(alist):
>     alist.sort

Doesn't do anything.

>     alist_tup_elements_reversed = []
>     for x in alist:
>         alist_tup_elements_reversed.append((x[1], x[0]))

You should learn how to use list comprehensions:
alist_tup_elements_reversed.append = [ (x[1], x[0]) for x in alist ]

>     alist_tup_elements_reversed.sort()
>     print alist_tup_elements_reversed
>
>     alist_tup_elements_reversed_and_reversed_again = []
>     for x in alist_tup_elements_reversed:
>         alist_tup_elements_reversed_and_reversed_again.append((x[1], x[0]))

Another list comp and you have pretty much reinvented
decorate-sort-undecorate (second time in a week for that!) - google it
or see my link in previous thread.

Kent
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to