> table.invert = function (t) > local i = {} > for k in pairs(t) do > i[t[k]] = true > end > return i > end A faster version that avoids double indexing: table.invert = function (t) local i = {} for k,v in pairs(t) do i[v] = true end return i end