[CentralOH] Python reversed() Question
Fandi Peng
fandi.814 at gmail.com
Fri Apr 20 03:48:05 CEST 2012
Yes..It works! and it's way more clean than what I wrote before.
: )
On Thu, Apr 19, 2012 at 9:19 PM, Kris Hardy <kris at rkrishardy.com> wrote:
> On 4/19/2012 7:16 PM, Kris Hardy wrote:
>
> sorted([("D3","E4"), ("A3","B2"),("A2","C4")...], lambda item: item[1])
>
> Oops...
> sorted([("D3","E4"), ("A3","B2"),("A2","C4")...], key=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
>
>
>
>
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> http://mail.python.org/mailman/listinfo/centraloh
>
More information about the CentralOH
mailing list