Logo

Programming-Idioms

History of Idiom 118 > diff from v23 to v24

Edit summary for version 24 by Bug38:
New Lua implementation by user [Bug38]

Version 23

2017-04-29, 07:09:17

Version 24

2017-08-21, 12:40:01

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
local hash = {}
local res = {}
for _,v in ipairs(test) do
   if (not hash[v]) then
       res[#res+1] = v
       hash[v] = true
   end
end
Doc URL
https://stackoverflow.com/a/20067270