How to “zip” or “rotate” a variable number of lists?

后端 未结 8 1649
广开言路
广开言路 2020-11-27 20:47

If I have a list containing an arbitrary number of lists, like so:

var myList = new List>()
{
    new List() { \"a\",          


        
8条回答
  •  甜味超标
    2020-11-27 20:56

    You can condense for loops using Range:

    var result = Enumerable.Range(0, myList.Min(l => l.Count))
        .Select(i => myList.Select(l => l[i]).ToList()).ToList();
    

提交回复
热议问题