Nice explanation about the built-in
enumerate function, @Zhio!
for idx, soldier in enumerate(['Skywalker', 'Vader']):
Is equivalent to:
for idx, soldier in [(0, 'Skywalker'), (1, 'Vader')]:
Now, what hasn’t been well explained yet is sequence unpacking. It allows assigning values from a sequence to variables:
idx, soldier = (0, 'Skywalker')
print idx # 0
print solider # 'Skywalker'
Now you should be able to piece everything together. The
enumerate function will return a sequence¹ of tuples containing index and value pairs, then the for-loop will iterate over this sequence of tuples and unpack each tuple into two variables in each iteration.
enumerate actually returns an iterator object, but that’s not really important for this topic as the for-loop consumes these seamlessly (just like any sequence).