Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Perl

Idiom #218 List intersection

Create the list c containing all unique elements that are contained in both lists a and b.
c should not contain any duplicates, even if a and b do.
The order of c doesn't matter.

my %u;
$u{$_} = 1 for @a, @b;
my @c = keys %u;

We create a hash u to collect only unique elements. Each one is a key to the hash
(def c (clojure.set/intersection (set a) (set b)))

New implementation...
< >
programming-idioms.org