Home
Blog
List Dedup Across Languages
Updated
Dot Net Perls

List Dedup Across Languages

Programmers are usually the kind of people who like to have everything organized—after all, a large part of programming is organizing data structures in programs. Consider a list that has many elements—and some of them may be repeated or duplicates. Programming languages often offer built-in methods to eliminate the duplicates.

In the C# language, we have a method called Distinct that is part of System.Linq. When called, it eliminates duplicates in an IEnumerable and returns the result—we may need to call ToList to get back to a List.

In Rust, we have a dedup function on the Vector type. This requires that the vector be sorted (or in groups of equal elements), or it will not work correctly—it works by looping through the elements and checking to see if there are any duplicates next to each other. If you are going to rewrite it in Rust, remember dedup.

In Go, we have a function in the slices package called slices.Compact. This works the same as the Rust dedup function—it removes repeated elements in a sorted slice. The slice must be sorted (or have same elements next to each other somehow).

Dot Net Perls is a collection of pages with code examples, which are updated to stay current. Programming is an art, and it can be learned from examples.
Donate to this site to help offset the costs of running the server. Sites like this will cease to exist if there is no financial support for them.
Sam Allen is passionate about computer languages, and he maintains 100% of the material available on this website. He hopes it makes the world a nicer place.
An RSS feed is available for this blog.
Home
Changes
© 2007-2025 Sam Allen