Logo

Programming-Idioms

History of Idiom 118 > diff from v29 to v30

Edit summary for version 30 by Bart:
New Pascal implementation by user [Bart]

Version 29

2018-08-29, 14:03:16

Version 30

2019-01-02, 11:08:40

Idiom #118 List to set

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

Illustration

Idiom #118 List to set

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

Illustration
Code
for i := Low(X) to High(X) do Include(Y,X[i]);
Comments bubble
Sets never have repeated values in Pascal. Adding a value that already is in the set leaves the set unchanged (and does not raise any error).