Loop over two or more sequences at the same time : zip « Buildin Function « Python






Loop over two or more sequences at the same time

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)


           
       








Related examples in the same category

1.Generator ExpressionsGenerator Expressions
2.Zip a two listsZip a two lists
3.Read element in a zipped listRead element in a zipped list
4.Zip three tuplesZip three tuples
5.Difference between zip and mapDifference between zip and map
6.Zip function demo: returns a list of tuplesZip function demo:  returns a list of tuples