locked
How to get the unification of the keys set of dictionaries? RRS feed

  • Question

  • Hi,

     I have a List of Dictionaries and I need to merge them according to their keys , i.e , if I have the following two dictionaries:

    KEY, VALUE

    18,0

    19,1

    15,2

    13,3

    ===

    19,0

    12,1

    13,2

    14,3

    ===

    So, I need to get the following result;

    18,0

    19,1

    15,2

    13,3

    12,4

    14,5

    I have used the following statement:

    unified_ht = unified_ht.Union(pageIDs_Hashtables_List[ht]).GroupBy(a => a.Key).ToDictionary(a => a.Key, a => a.First().Value);

    and got the following result:

    18,0

    19,1

    15,2

    13,3

    12,1

    14,3

    So, how to correct my result?

    thanks so much in advance,

    Regards,

    Aya.


    Aya Zoghby

    Saturday, December 15, 2012 8:40 PM

Answers

  • Why do you think your output should have 12, 4 and 14, 5?  They do not exist in your input, but rather 12, 1 and 14, 3 do exist in your input.

    --
    Mike
    • Marked as answer by ZoghbyAya Sunday, December 16, 2012 3:34 PM
    Sunday, December 16, 2012 2:38 AM