Logo

Programming-Idioms

History of Idiom 118 > diff from v5 to v6

Edit summary for version 6 by :
New D implementation by user [cym13]

Version 5

2016-01-24, 03:07:10

Version 6

2016-01-24, 03:09:57

Idiom #118 List to set

Create set y from list x.
x may contain duplicates. y is unordered and has no repeated values.

Idiom #118 List to set

Create set y from list x.
x may contain duplicates. y is unordered and has no repeated values.

Code
bool[typeof(x[0])] y;

foreach (e ; x)
    y[e] = true;
Comments bubble
D doesn't have a set type so I'm using an associative array here. The "typeof(x[0])" trick is because the type of the elements of x wasn't given, we wouldn't need it in practice.