我有一张桌子,我在其中传递名字: names = {‘Sachin’,’Ponting’,’Dhoni’} 在其他表格中,我传递的是国名: country = {“India”,“Australia”,“India”} 我想要输出表: out_table = {Sachin =“In
names = {‘Sachin’,’Ponting’,’Dhoni’}
在其他表格中,我传递的是国名:
country = {“India”,“Australia”,“India”}
我想要输出表:
out_table = {Sachin =“India”,Ponting =“Australia”,Dhoni =“India”}
这是一个直截了当的尝试:names = {'Sachin', 'Ponting', 'Dhoni'} countries = {"India", "Australia", "India"} function table_map(names, countries) local out = {} for i, each in ipairs(names) do out[each] = countries[i] end return out end out_table = table_map(names, countries)
Live repl demo.