Consider replacing
range(len(highlights))
with enumerate(highlights)
57 highlights.sort(key=lambda x: x[0])
58
59 # Remove overlapping ones
60 for hl_idx in range(len(highlights)):61 if hl_idx >= len(highlights):
62 break
63 elref = highlights[hl_idx]
Description
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(...)
.
Not Preferred:
for index in range(len(mylist)):
...
Preferred:
for index, element in enumerate(mylist):
...