pylint woes

Chris Angelico rosuav at gmail.com
Sat May 7 13:01:17 EDT 2016


On Sun, May 8, 2016 at 2:51 AM, DFS <nospam at dfs.com> wrote:
> [1]
> pylint says "Consider using enumerate instead of iterating with range and
> len"
>
> the offending code is:
> for j in range(len(list1)):
>   do something with list1[j], list2[j], list3[j], etc.
>
> enumeration would be:
> for j,item in enumerate(list1):
>   do something with list1[j], list2[j], list3[j], etc.
>
> Is there an advantage to using enumerate() here?

The suggestion from a human would be to use zip(), or possibly to
change your data structures.

for item1, item2, item3 in zip(list1, list2, list3):
    do something with the items

ChrisA



More information about the Python-list mailing list