Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove duplicates items in list (Raku)

Tags:

raku

FAQ: In Raku, how to remove duplicates from a list to only get unique values?

my $arr = [1, 2, 3, 2, 3, 1, 1, 0];
# desired output [1, 2, 3, 0]
like image 399
Tinmarino Avatar asked Mar 25 '20 16:03

Tinmarino


People also ask

How do I remove duplicates from a list set?

Remove duplicates from list using Set. To remove the duplicates from a list, you can make use of the built-in function set(). The specialty of set() method is that it returns distinct elements. We have a list : [1,1,2,3,2,2,4,5,6,2,1].

How do I remove a specific repeated item from a list in Python?

If the order of the elements is not critical, we can remove duplicates using the Set method and the Numpy unique() function. We can use Pandas functions, OrderedDict, reduce() function, Set + sort() method, and iterative approaches to keep the order of elements.

How do I remove duplicates in list elixir?

Thanks to the Enum module, in Elixir we can trivially remove duplicates from a list. In the following example, we take a list of integers and pass it to the Enum. uniq/1 function which removes duplicates from the list without altering the original order of the remaining elements.


1 Answers

  1. Use The built-in unique
@arr.unique  # (1 2 3 0)
  1. Use a Hash (alias map, dictionary)
my %unique = map {$_ => 1}, @arr;
%unique.keys;  # (0 1 2 3) do not rely on order
  1. Use a Set: same method as before but in one line and optimized by the dev team
set(@arr).keys
  • Links:
    • Answer on Roseta Code
    • Hash solution on Think Perl6
    • Same question for Perl, Python -> always same methods: a Hash or a Set
like image 192
Tinmarino Avatar answered Nov 03 '22 21:11

Tinmarino