[Tutor] solution for for loop?
Peter Otten
__peter__ at web.de
Sat Oct 25 13:41:18 CEST 2014
Clayton Kirkwood wrote:
> description_string=code_string=''
>
> description = code = 'a'
>
> for (description_position, code_position) in (description, code):
>
> print(description_position,code_position)
> I have tried variations on this for statement, and it doesn't work:<)))
> Both description and code have the same size array. I was hoping that some
> derivative of this for would bring in a new description_position value,
> and code_position value.
You want zip():
>>> colors = [ "red", "green", "yellow"]
>>> fruit_list = ["cherry", "apple", "banana"]
>>> for color, fruit in zip(colors, fruit_list):
... print(color, fruit)
...
red cherry
green apple
yellow banana
More information about the Tutor
mailing list