Mega Code Archive

 
Categories / Python / Buildin Function
 

Loop over two or more sequences at the same time

# Loop over two or more sequences at the same time,  # the entries can be paired with the zip() function. questions = ['A', 'B', 'C'] answers = ['a', 'b', 'c'] for q, a in zip(questions, answers):      print 'What is your %s?  It is %s.' % (q, a)