How to sort a list by the 2nd tuple element in python and C#
Posted
by user350468
on Stack Overflow
See other posts from Stack Overflow
or by user350468
Published on 2010-05-26T01:33:38Z
Indexed on
2010/05/26
1:41 UTC
Read the original article
Hit count: 239
I had a list of tuples where every tuple consists of two integers and I wanted to sort by the 2nd integer. After looking in the python help I got this:
sorted(myList, key=lambda x: x[1])
which is great. My question is, is there an equally succinct way of doing this in C# (the language I have to work in)? I know the obvious answer involving creating classes and specifying an anonymous delegate for the whole compare step but perhaps there is a linq oriented way as well. Thanks in advance for any suggestions.
© Stack Overflow or respective owner