Here is the code to emulate python zip function.
def myzip(*args):
return [tuple(a[i] for a in args) for i in range(len(min(args, key=len)))]
print(myzip([10, 20,30], 'abc'))
#output: [(10, 'a'), (20, 'b'), (30, 'c')]
If I remove the tuple(), the output will be: [10, 20, 30, 'a', 'b', 'c']
I don't quite understand how list comprehension works when we just add tuple()
So after each 2 loop, it yield a value and automatically add it to internal list before turning into tuple and finally add them to outer list?
For eg:
Loop 1: 10 Loop 2: a Add to [10,a] -> tuple([10,a]) -> (10,a)
Loop 2: 20 Loop 2: b Add to [20,b] -> tuple([20,b]) -> (20,b)
....