complex sorting in c# equivalent to pythons itemgetter,
Solution 1:
I see in the sample data that importance
is already sorted so the most important items come in order. I will continue assuming this is true. If not, sorting that set adds one line of code (importance = importance.OrderByDescending(i => i.Item2).ToList();
)
That out of the way, this should do the job:
//seed result with a valid IOrderedEnumerable for first level
var result = ls.OrderBy(ba => ba[importance[0].Item1]?0:1);
// check remaining items
for (int i = 1; i<importance.Count; i++)
{
int y = i; //prevent closure over i
result = result.ThenBy(ba => ba[importance[y].Item1]?0:1);
}
ls = result.ToList();
See it work here:
https://dotnetfiddle.net/qntayC