Dynamically cross-join multiple different-size collections together in Linq (C#)

You could create an extension method like the following: public static class EnumerableExtensions { public static IEnumerable<TValue []> Permutations<TKey, TValue>(this IEnumerable<TKey> keys, Func<TKey, IEnumerable<TValue>> selector) { var keyArray = keys.ToArray(); if (keyArray.Length < 1) yield break; TValue [] values = new TValue[keyArray.Length]; foreach (var array in Permutations(keyArray, 0, selector, values)) yield return array; } static … Read more

How can I make a list of dictionaries according to the Cartesian product of values in a source dictionary (“explode” the dictionary)?

I think you want the Cartesian product, not a permutation, in which case itertools.product can help: >>> from itertools import product >>> d = {‘Color’: [‘Red’, ‘Yellow’], ‘Size’: [‘Small’, ‘Medium’, ‘Large’]} >>> [dict(zip(d, v)) for v in product(*d.values())] [{‘Color’: ‘Red’, ‘Size’: ‘Small’}, {‘Color’: ‘Red’, ‘Size’: ‘Medium’}, {‘Color’: ‘Red’, ‘Size’: ‘Large’}, {‘Color’: ‘Yellow’, ‘Size’: ‘Small’}, {‘Color’: … Read more