zipping/merging two sorted lists
c#
Solution
This is what I've got:
SortedDictionary<decimal, List<long>> merged = new SortedDictionary<decimal, List<long>>
(
A.Union(B)
.ToLookup(x => x.Key, x => x.Value)
.ToDictionary(x => x.Key, x => new List<long>(x))
);
EDIT: Above solution selects keys not included in both collections. This should select where keys are same:
SortedDictionary<decimal, List<long>> merged = new SortedDictionary<decimal, List<long>>
(
A.Where(x=>B.ContainsKey(x.Key))
.ToDictionary(x => x.Key, x => new List<long>(){x.Value, B[x.Key]})
);
Problem
i have two sorted dictionaries both with the type signature i.e. ``` SortedDictionary<decimal, long> A SortedDictionary<decimal, long> B ``` I want to merge the two lists where the key is the same, thus creating a new list like ``` SortedDictionary<decimal, KeyValuePair<long,long>> or SortedDictionary<decimal, List<long>> ``` This may not be the best way of approacing the situation but could someone give me a heads up on how to do this or a better way to approach it.