Do not use for i in range(len(<array>))

Metadata

ID: python-best-practices/no-range-loop-with-len

Language: Python

Severity: Error

Category: Best Practices

Description

Do not iterate over an array using for in range(len(array)). Use instead for i in array.

Learn More

Non-Compliant Code Examples

for i in range(len(tab)):  # iterate directly over the array
  bla(tab[i])
for i in range(len(tab)):  # iterate directly over the array
  tab[i] = bla

Compliant Code Examples

for i in tab:
  bla(i)