[英]How to convert IEnumerable<IEnumerable<IGrouping<int,string>>> to IEnumerable<IEnumerable<string>>
I'm trying to partition some comma separated lines into groups of size 2 at max. 我正在尝试将一些用逗号分隔的行最大划分为大小为2的组。 How can i convert the collection of groups to list of lists as below? 如何将群组集合转换为以下列表列表? I expect the partitions to be 3 first and then 4 after grouping. 我希望分区首先是3,然后在分组后是4。
List<string> chunk = new List<string>()
{
"a,b,c",
"a,d,e",
"b,c,d",
"b,e,d",
"b,f,g",
"e"
};
var partitons = chunk.GroupBy(c => c.Split(',')[0], (key, g) => g);
var groups = partitons.Select(x => x.Select((i, index) => new { i, index }).GroupBy(g => g.index / 2, e => e.i));
IEnumerable<IEnumerable<string>> parts = groups.Select(???)
这就是我想要的
var parts = groups.SelectMany(x => x).Select(y => y.Select(z => z));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.