任何人都可以提供从数字索引中删除重复项的替代方法
将保留重复记录的表?,这个可以工作,但在
的表上
1000 个或更多条目似乎会占用 cpu,从而导致“无响应”
在应用程序中嵌入了lua。
local Dupes ={} local t2 = {}; for i,v in pairs(t1) do Count = table.getn(t2) t2[v] = i Count1 = table.getn(t2) if Count == Count1 then table.insert(Dupes,v) end end
最佳答案
我真的不明白使用getn
的目的。只需测试一下它是否已经存在:
local Dupes ={}
local t2 = {};
for i,v in pairs(t1) do
if(t2[v] ~= nil) then
table.insert(Dupes,v)
end
t2[v] = i
end
关于Lua表删除重复项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11075034/