using System.Collections.Generic;
private static void Main(string[] args)
var dictOfLists = new Dictionary<string, List<string>>
["foo"] = new List<string> { "a", "b", "c" },
["bar"] = new List<string> { "d" },
["baz"] = new List<string> { "e", "a" }
var result = BuildDictionary(dictOfLists);
Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(result, new System.Text.Json.JsonSerializerOptions { WriteIndented = false }));
private static Dictionary<TKey, TValue>[] BuildDictionary<TKey, TValue>(Dictionary<TKey, List<TValue>> dict) where TKey : notnull
int[] lengths = dict.Select(d => d.Value.Count()).ToArray();
int size = lengths.Aggregate(1, (prev, val) => prev * val);
var result = new Dictionary<TKey, TValue>[size];
for (int i = 0; i < result.Length; i++) { result[i] = new Dictionary<TKey, TValue>(); }
for (int row = 0; row < size;)
for (int i = 0; i < repeats; i++)
foreach (var val in d.Value)
result[row].Add(key, val);
repeats *= d.Value.Count;