Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I sort this list?

I have a list of lists.

List<List<T>> li = {
   {a1,a2,a3 ... aN},
   {b1,b2,b3 ... bN},
   ...
};

double foo(List<T> list)
{
    // do something 
    // e.g {1,2,3} 
    // it = 1 + 2 + 3

    return it;
}

Now I want to sort li in such a way that higher the foo(x) for a x higher it should appear in a sorted list.

What is the best way in C#/Python/any other lang to this?

like image 408
Pratik Deoghare Avatar asked Nov 28 '22 05:11

Pratik Deoghare


1 Answers

With a little bit of LINQ:

var q = from el in li
        orderby foo(el)
        select el;
li = q.ToList();
like image 92
Henk Holterman Avatar answered Nov 29 '22 19:11

Henk Holterman