for loop with zip and enumerate 1

for loop with zip and enumerate

for i, t in enumerate(zip(names, ages)):
    print(i, t[0], t[1])

Here is what the above code is Doing:
1. The enumerate function returns a tuple containing a count (from start which defaults to 0) and the values obtained from iterating over sequence.
2. The for loop iterates over the tuple returned by enumerate() and unpacks the tuple into i and t.
3. The tuple t is unpacked into two variables, name and age.

Similar Posts