Logo

Programming-Idioms

History of Idiom 119 > diff from v41 to v42

Edit summary for version 42 by anonymous:
[D] fix typo

Version 41

2018-04-11, 21:35:32

Version 42

2018-10-06, 15:52:11

Idiom #119 Deduplicate list

Remove duplicates from list x.
Explain if original order is preserved.

Illustration

Idiom #119 Deduplicate list

Remove duplicates from list x.
Explain if original order is preserved.

Illustration
Extra Keywords
deduplicate dupe dupes redundant redundancy
Extra Keywords
deduplicate dupe dupes redundant redundancy
Imports
import std.algorithm;
import std.array;
Imports
import std.algorithm;
import std.array;
Code
x = x.sort.uniq.array;
Code
x = x.sort.uniq.array;
Comments bubble
uniq takes and output a range which could be infinite so it only looks for adjacent duplicates. That's why we sort x beforehand.
Comments bubble
uniq takes an output a range which could be infinite so it only looks for adjacent duplicates. That's why we sort x beforehand.
Doc URL
http://dlang.org/phobos/std_algorithm_iteration.html#.uniq
Doc URL
http://dlang.org/phobos/std_algorithm_iteration.html#.uniq