Ding, ding, ding. Winner, winner, winner. Peter wins the prize, suggesting
the use of zip(). This allowed me to pull two different strings from two
different lists at one time in a for loop.

for description_position, code_position in zip(description, code):

Yes!!  Thank you Peter

Clayton

!-----Original Message-----
!From: Tutor [mailto:[email protected]] On
!Behalf Of Peter Otten
!Sent: Saturday, October 25, 2014 4:41 AM
!To: [email protected]
!Subject: Re: [Tutor] solution for for loop?
!
!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
!
!
!_______________________________________________
!Tutor maillist  -  [email protected]
!To unsubscribe or change subscription options:
!https://mail.python.org/mailman/listinfo/tutor



_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to