Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing Duplicates "ABD" "BAD" "DAB" from a list of permutations

Tags:

c#

I have a rather large list of strings that contains duplicates in the sense that if I only care if A,B,C are in a result, but not what order they are in. I looked for many other duplication removal solutions, but they typically only work for exact values(which I understand since these elements aren't exact dups, but more spurious or superfluous results.) I already have the list and didn't create it, so changing the selection is not an option.

like image 498
StuckOnSimpleThings Avatar asked Dec 26 '22 04:12

StuckOnSimpleThings


1 Answers

Simply sort the elements within each item first.

listOfStrings.Select(s => new string(s.OrderBy(c => c))).Distinct().ToList();

You see what I mean - sort the chars. I'll check the syntax of this momentarily..

like image 166
Kieren Johnstone Avatar answered Feb 13 '23 20:02

Kieren Johnstone