lookup.SelectMany(x => x)
only returns values. Is there a way to retain keys associated with them?
CodePudding user response:
Lookup<TKey, TValue>
implements IEnumerable<IGrouping<TKey,TElement>>
and IGrouping<TKey,TElement>
exposes Key
property so just use it:
var listOfValueTuples = lookup
.SelectMany(g => g.Select(v => (g.Key, v)))
.ToList();