One frequently finds expressions of this type in python questions on SO. Either for just accessing all items of the iterable
for i in range(len(a)): prin
If you need to work with indices of a sequence, then yes - you use it... eg for the equivalent of numpy.argsort...:
>>> a = [6, 3, 1, 2, 5, 4] >>> sorted(range(len(a)), key=a.__getitem__) [2, 3, 1, 5, 4, 0]