something like this:
1 | local peoples = { 'joe' , 'jogn' , 'gfajkg' } |
2 | local secrets = { 'agag' , 'gafggf' , 'gagfdg' } |
3 | local reasons = { 'sometyhing' , 'another thing' , 'ffszdgsg' } |
4 |
5 | for index, name in next , peoples do |
6 | local secret = secrets [ index ] |
7 | local reason = reasons [ index ] |
8 | print (name, 'is hiding' , secret, 'because' , reason) |
9 | end |
could be:
1 | local peoples = { 'joe' , 'jogn' , 'gfajkg' } |
2 | local secrets = { 'agag' , 'gafggf' , 'gagfdg' } |
3 | local reasons = { 'sometyhing' , 'another thing' , 'ffszdgsg' } |
4 |
5 | for name, secret, reason in zip(peoples, secrets, reasons) do |
6 | print (name, 'is hiding' , secret, 'because' , reason) |
7 | end |
01 | local ArbitraryArrayA = { 1 } |
02 | local ArbitraryArrayB = { 2 } |
03 | local ArbitraryArrayC = { 3 } |
04 |
05 |
06 | local function CollectAttributesFromIndex(Index, Tables) |
07 | local Attributes = { } |
08 | --------------- |
09 | for _, Attribute in ipairs (Tables) do |
10 | table.insert(Attributes, Attribute [ Index ] ) |
11 | end |
12 | --------------- |
13 | return Attributes |
14 | end |
15 |
No, but you can write your own
01 | local function zip(First, Second, Third) |
02 | local Index = 0 |
03 |
04 | return function () |
05 | Index + = 1 |
06 |
07 | local NextFirst = First [ Index ] |
08 | local NextSecond = Second [ Index ] |
09 | local NextThird = Third [ Index ] |
10 |
11 | if not NextFirst or not NextSecond or not NextFirst then |
12 | return nil |
13 | end |
14 |
15 | return NextFirst, NextSecond, NextThird |
the way this works is that zip
returns a function which is being called every iteration, in the function i increment the index by 1 every time to create a loop, then it returns elements from each table with given index, if at least one of the elements is nil it breaks the loop.
I am not a pythoneer so i am not sure if this is how the function is supposed to work but i think it fits your example. You can adjust it how you need, i made it simple so you can understand it.