CipherIS
asked on
C# remove duplicates from list where there is more than one repeating char in the item.
I want to remove duplicates. Using the below example I want "Alpha" and "Gamma" removed from the list because "Alpha" has 2 A's and "Gamma" has two A's and two M's.
List<string> theList = new List<string>() { "Alpha", "Beta", "Gamma", "Delta" };
The values that should be returned should be distinct in each item. No duplicate letters.
List<string> theList = new List<string>() { "Alpha", "Beta", "Gamma", "Delta" };
The values that should be returned should be distinct in each item. No duplicate letters.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I tried to implement your suggestion but it doesn't work with what i'm actually working with. Thought if I gave a generic example it would work. Working on an app for a trader. Using permutations to build a list. Below is an example.
1, 2, 3 4, 5.
1,1,3,4,5 need to be eliminated because 1 exists more than 1 x.
5,4,3,2,1 needs to be eliminated because it has same combination as 1,2,3,4,5 regardless of order.
Thanks
public class ValuesModel
{
public string V01 { get; set; }
public string V02 { get; set; }
public string V03 { get; set; }
public string V04 { get; set; }
public string V05 { get; set; }
}
List<ValuesModel> values = new List<ValuesModel>();
values.Add(new ValuesModel()
{
V01 = 1, V02 = 2, V03 = 3, V04 = 4, V05 = 5,
});
values.Add(new ValuesModel()
{
V01 = 1, V02 = 1, V03 = 3, V04 = 4, V05 = 5,
});
values.Add(new ValuesModel()
{
V01 = 5, V02 = 4, V03 = 3, V04 = 3, V05 = 1,
});
Using above example of the three entries the only valid item should be1, 2, 3 4, 5.
1,1,3,4,5 need to be eliminated because 1 exists more than 1 x.
5,4,3,2,1 needs to be eliminated because it has same combination as 1,2,3,4,5 regardless of order.
Thanks
ASKER
Saige,
Thanks for the input. I did get this to work. I'll try to post later to see if there is a way to make it more efficient.
Thanks
Thanks for the input. I did get this to work. I'll try to post later to see if there is a way to make it more efficient.
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hope this problem is resolved by now.
With each individual string (like "Alpha") you could use the string's ToCharArray method to separate each character in the string.
Create a new List of Char objects that will be your test area... Step through each Char in the array and, just before adding it to the new list, use the list's Contains(T) method to see if the Char already exists. If it doesn't, add the character to the list and move on to the next character. If it does exist, you know you can remove the string from the original list, using the Remove(T) method and move on to the next string in the original list.