Logo

Programming-Idioms

History of Idiom 118 > diff from v25 to v26

Edit summary for version 26 by programming-idioms.org:
[Lua] No need for sample values

Version 25

2017-08-21, 12:41:36

Version 26

2017-08-21, 19:39:54

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