[CentralOH] Python reversed() Question

Kris Hardy kris at rkrishardy.com
Fri Apr 20 03:16:49 CEST 2012

sorted([("D3","E4"), ("A3","B2"),("A2","C4")...], lambda item: item[1])

On 4/19/2012 7:12 PM, Fandi Peng wrote:
> Hi guys, I have a question:
> Suppose I have a list, every element in the list is a tuple,
> every tuple has two elements,
> e.g. [("D3","E4"), ("A3", "B2"), ("A2","C4")....]
> Therefore, if I sorted the list, the tuples would be rearranged
> based on the first element of each tuple:
> e.g. [("A2","C4"), ("A3", "B2"), ("D3","E4")....]
> Now I want this list to be sorted based on the second element
> of each tuple:
> e.g. [("A3", "B2"), ("A2","C4"), ("D3","E4"),....]
> What's the simplest code could you come up to achieve
> this?
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> http://mail.python.org/mailman/listinfo/centraloh

More information about the CentralOH mailing list