I have:
List<string> list = new List<string>() { "a", "a", "b", "b", "r", "t" };
How can I get only "a","b"?
I tried to do like this:
List<string> list = new List<string>() { "a", "a", "b", "b", "r", "t" };
List<string> test_list = new List<string>();
test_list = list.Distinct().ToList();
Now test_list has {"a", "b", "r", "t"}
And then:
test_list = test_list.Except(list).ToList();
So that was my fail point, cause Except() deleted all elements.
Could you help me with solution?
Python list can contain duplicate elements.
List<string> list = new List<string>() { "a", "a", "b", "b", "r", "t" };
var dups = list.GroupBy(x => x)
.Where(x => x.Count() > 1)
.Select(x => x.Key)
.ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With