hug2wisdom / learnpython

note the points of learn python
0 stars 0 forks source link

dictionary #9

Open hug2wisdom opened 4 years ago

hug2wisdom commented 4 years ago
hug2wisdom commented 4 years ago

To loop over two or more sequences at the same time, the entries can be paired with the zip() function.

questions = ['name', 'quest', 'favorite color']
answers = ['lancelot', 'the holy grail', 'blue']
for q, a in zip(questions, answers):
    print('What is your {0}?  It is {1}.'.format(q, a))

# result
What is your name?  It is lancelot.
What is your quest?  It is the holy grail.
What is your favorite color?  It is blue.