Skip to content

Working with positions

Read · 1 of 2

enumerate gives position and value

for i, x in enumerate(nums): gives each position i together with its value x.

Careful: valid positions are 0 to len − 1. nums[len(nums)] is past the end and stops your program with an IndexError.