range(len(highlights))
with enumerate(highlights)
61 highlights.sort(key=itemgetter(0))
62
63 # Remove overlapping ones
64 for hl_idx in range(len(highlights)):65 if hl_idx >= len(highlights):
66 break
67 elref = highlights[hl_idx]
Using range(len(...))
is not pythonic. Python does not have not index-based loops. Instead, it uses collection iterators.
Python has a built-in method enumerate
which adds a counter to an iterable.
Using this, you can access the counter and the value from the iterable at the same time.
It is therefore recommended to replace range(len(...))
with enumerate(...)
.
for index in range(len(mylist)):
...
for index, element in enumerate(mylist):
...