Owain Clarke, 10.02.2010 17:57:
> data.sort(key=lambda x:x[0])
> data.sort(key=lambda x:x[1])

Two things to note:

1) you can use the operator module, specifically operator.itemgetter

2) given that you have lists as items in the 'data' list, it's enough to
call sort() once, as the comparison of lists is defined as the comparison
of each item to the corresponding item of the other list. If you want to
sort based on the second item before the first item, it's best to exchange
both items before sorting and swap them back afterwards.

Stefan

_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to