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 6569147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:35:25+00:00 2026-05-25T14:35:25+00:00

Suppose I have a dictionary object of String, List (of String) that looks like.

  • 0

Suppose I have a dictionary object of String, List (of String) that looks like.

BU1
--All, BU
CON1
--ALL, EMP, CONF, CON1
SS1
--ALL, EMP, SS

How can I get an object that contains a lists of distinct matches like so…

ALL, ALL, ALL --> Distinct is ALL
ALL, EMP, ALL --> Distinct is ALL, EMP
ALL, EMP, EMP --> Distinct is ALL, EMP --> exists don't add
BU, ALL, ALL --> Distinct is BU, ALL
BU, EMP, ALL --> Distinct is BU, EMP, ALL
BU, EMP, EMP --> Distinct is BU, EMP

etc

This should be really simple and I’ve played with LINQ Intersect and Except and recursive functions but I haven’t hit on a winning combination.

This list is just a mini example. The real list would be much bigger in both breadth and width.

Thanks in advance.

  • 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-25T14:35:26+00:00Added an answer on May 25, 2026 at 2:35 pm

    I think you’re looking to perform the cartesian product of each of your lists and get the distinct tuples (each tuple containing only distinct values).

    This algorithm isn’t terribly efficient; it’s going to generate a number of sets equal to the product of the lengths of all your lists and compare these sets to get the final distinct result. You would need to make some minor modifications to make it case-insensitive, but you didn’t say if that was required.

    Dictionary<string, List<string>> Data = new Dictionary<string, List<string>>()
    {
        {"BU1", new List<string>(){"ALL", "BU"}},
        {"CON1", new List<string>(){"ALL", "EMP", "CONF", "CON1"}},
        {"SS1", new List<string>(){"ALL", "EMP", "SS"}},
    };
    
    IEnumerable<IEnumerable<string>> Empty = Enumerable.Repeat(Enumerable.Empty<string>(), 1);
    Data.Aggregate(Empty, 
        (accumulator, kvp) => 
            from a in accumulator 
            from i in kvp.Value 
            select a.Concat(Enumerable.Repeat(i, 1)))
        .Select(set => new HashSet<string>(set))
        .Distinct(HashSet<string>.CreateSetComparer());
    

    This produces the following output sets:

    HashSet<String> (1 item)
    ALL
    HashSet<String> (2 items)
    ALL
    EMP
    HashSet<String> (2 items)
    ALL
    SS
    HashSet<String> (3 items)
    ALL
    EMP
    SS
    HashSet<String> (2 items)
    ALL
    CONF
    HashSet<String> (3 items)
    ALL
    CONF
    EMP
    HashSet<String> (3 items)
    ALL
    CONF
    SS
    HashSet<String> (2 items)
    ALL
    CON1
    HashSet<String> (3 items)
    ALL
    CON1
    EMP
    HashSet<String> (3 items)
    ALL
    CON1
    SS
    HashSet<String> (2 items)
    BU
    ALL
    HashSet<String> (3 items)
    BU
    ALL
    EMP
    HashSet<String> (3 items)
    BU
    ALL
    SS
    HashSet<String> (2 items)
    BU
    EMP
    HashSet<String> (3 items)
    BU
    EMP
    SS
    HashSet<String> (3 items)
    BU
    CONF
    ALL
    HashSet<String> (3 items)
    BU
    CONF
    EMP
    HashSet<String> (3 items)
    BU
    CONF
    SS
    HashSet<String> (3 items)
    BU
    CON1
    ALL
    HashSet<String> (3 items)
    BU
    CON1
    EMP
    HashSet<String> (3 items)
    BU
    CON1
    SS
    

    Update: Here is the same algorithm in VB.NET (it looks very much the same):

    Dim Empty As IEnumerable(Of IEnumerable(Of String)) = Enumerable.Repeat(Enumerable.Empty(Of String)(), 1)
    Data.Aggregate(Empty, _
        Function(accumulator, kvp) _
            From a in accumulator _
            From i in kvp.Value _
            Select a.Concat(Enumerable.Repeat(i, 1))) _
        .Select(Function([set]) New HashSet(Of String)([set])) _
        .Distinct(HashSet(Of String).CreateSetComparer())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a Dictionary like so: Dictionary<string, Stream> How can I get a
Suppose I have a Dictionary<string, string> instance, like this one: { { a, 1
Suppose I have Dictionary like this: Dictionary<string, string> values = new Dictionary<string, string>() {
Suppose that I have a Dictionary<string, string> . The dictionary is declared as public
Suppose you have a dictionary that contains valid words. Given an input string with
Suppose I have the following dictionary and list: my_dictionary = {1:hello, 2:goodbye, 3:World, sand:box}
Suppose I have a Collection of some kind that itself contains Collections; e.g., Dictionary(Of
Suppose I have a static method of my class that returns an object of
I have a dictionary object that I am pulling data out of. The field
i am implementing dictionary in which key is a string keyword.suppose i have following

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.