I\'d like to partition a list into a list of lists, by specifying the number of elements in each partition.
For instance, suppose I have the list {1, 2, ... 11}, and
You could use an extension method:
public static IList
object currentKey = null;
foreach (T item in input ?? Enumerable.Empty())
{
currentKey = partitionFunc(item);
if (!partitions.ContainsKey(currentKey))
{
partitions[currentKey] = new HashSet();
}
partitions[currentKey].Add(item);
}
return partitions.Values.ToList();
}