pylint woes

MRAB python at mrabarnett.plus.com
Sat May 7 22:21:33 EDT 2016


On 2016-05-08 03:14, Stephen Hansen wrote:
> On Sat, May 7, 2016, at 06:16 PM, DFS wrote:
>
>> Why is it better to zip() them up and use:
>>
>> for item1, item2, item3 in zip(list1, list2, list3):
>>       do something with the items
>>
>> than
>>
>> for j in range(len(list1)):
>>     do something with list1[j], list2[j], list3[j], etc.
>
> Although Chris has a perfectly good and valid answer why conceptually
> the zip is better, let me put forth: the zip is simply clearer, more
> readable and more maintainable.
>
> This is a question of style and to a certain degree aesthetics, so is
> somewhat subjective, but range(len(list1)) and list1[j] are all
> indirection, when item1 is clearly (if given a better name then 'item1')
> something distinct you're working on.
>
+1

If you're iterating through multiple sequences in parallel, zip is the 
way to go.




More information about the Python-list mailing list