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.
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.
This produces the following output sets:
Update: Here is the same algorithm in VB.NET (it looks very much the same):