On 11/03/2016 01:56, Martin A. Brown wrote:

for i in range(len(names)):
     print (names[i],totals[i])

Always a code smell when range() and len() are combined.

Any other way of traversing two lists in parallel?

Yes.  Builtin function called 'zip'.

   https://docs.python.org/3/library/functions.html#zip

Toy example:

   import string
   alpha = string.ascii_lowercase
   nums = range(len(alpha))
   for N, A in zip(nums, alpha):
       print(N, A)

Good luck,

-Martin


Which would usually be written for N, A in enumerate(alpha):

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to