Does Lua have any statement equivalent to the "in" statement of python?
Example:
if "word" in variable:
Does Lua have any statement equivalent to the "in" statement of python?
Example:
if "word" in variable:
Lua has no equivalent of Python's in operator, but if you know what container type you want to emulate, it's easy to write a function for it.
strThe true argument ensures that the substring is treated literally and not as a pattern. See string.find for details.
local function inString(s, substring)
return s:find(substring, 1, true)
end
listlocal function inArray(array, x)
for _, v in ipairs(array) do
if v == x then
return true
end
end
return false
end
dictlocal function inKeys(t, k)
return t[k] ~= nil
end