Is there a need for range(len(a))?

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]

Leave a Comment