Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6363103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:59:37+00:00 2026-05-24T23:59:37+00:00

I need a little assistance developing an algorithm that merges Lists of Lists based

  • 0

I need a little assistance developing an algorithm that merges Lists of Lists based on matching like key/value pairs.

In the example below I have 3 List> instances which I would like to reduce/merge using a Merge method call. The object of the Merge is to take instances that contain any matching key/value pair and merge both lists into a new list containing all of the pairs from both lists. So in this example the Merge method should condense the 3 lists into 1 because list1 and list2 both containing matching key names and values for “key1” and “key2”. Then the new merged list of list1 and list2 would further merge with list3 because they both contain matching key names and values for “key4”.

Anyone have any ideas on an efficient algorithm? I’m currently using a recursive method that is extremely slow as it compares every list to every other list.

    var list1 = new List<KeyValuePair<string, string>> { 
        new KeyValuePair<string,string>("key1","2"), 
        new KeyValuePair<string,string>("key2","5"),
        new KeyValuePair<string,string>("key3","20")
    };

    var list2 = new List<KeyValuePair<string, string>> { 
        new KeyValuePair<string,string>("key1","2"), 
        new KeyValuePair<string,string>("key2","5"),
        new KeyValuePair<string,string>("key4","10"),
        new KeyValuePair<string,string>("key5","A"),
        new KeyValuePair<string,string>("key6","B"),
        new KeyValuePair<string,string>("key7","C")
    };

    var list3 = new List<KeyValuePair<string, string>> { 
        new KeyValuePair<string,string>("key10","2"), 
        new KeyValuePair<string,string>("key20","5"),
        new KeyValuePair<string,string>("key4","10"),
        new KeyValuePair<string,string>("key40","2")
    };

    var fullList = new List<IList<KeyValuePair<string, string>>>();

    fullList.Add(list1); 
    fullList.Add(list2); 
    fullList.Add(list3);

    List<IList<KeyValuePair<string, string>>> mergedList = fullList.Merge();

    /*
     output should be a single a single IList<KeyValuePair<string, string>> with a count of 10 KeyValuePair<string,string> items
     mergedList would contain the following key/value pairs

        "key1","2" 
        "key2","5"
        "key3","20"
        "key4","10"
        "key5","A"
        "key6","B"
        "key7","C"
        "key10","2" 
        "key20","5"
        "key40","2"
    */
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:59:38+00:00Added an answer on May 24, 2026 at 11:59 pm

    See this post on linq set operators http://geekswithblogs.net/BlackRabbitCoder/archive/2011/05/05/c.net-little-wonders-the-linq-set-operations—-theyre-not.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just need a little bit of Javascript to warn people that press the back
I need a little advice. I've got windows service that runs at night. In
I havent done CSS in awhile (~5-7yrs). So i need a little assistance in
Ok guys. I've begun developing a little sparetime project that might become big someday.
i'm very new to linq to sql and in need of a little assistance.
I need a little assistance getting email addresses only from within their POSSIBLY INCLUDED
This is a really stupid question, but I need a little reassurance/assistance. I have
Need a little help with a regex I'm trying to match a string that
I need a little help about a PHP FB app. Matter is that I
i need a little bit of help with some jquery thing that i'm sure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.