Looping techniques Flashcards
1
Q
how to loop key pair value in a dictionary?
A
for k, v in d.items():
2
Q
how to value index, value in a sequence?
A
for i, v in enumerate(list):
3
Q
how to loop over two or more sequence at the same time?
A
questions = [‘name’, ‘quest’, ‘favorite color’]
answers = [‘lancelot’, ‘the holy grail’, ‘blue’]
for q, a in zip(questions, answers):
print(q,a)
4
Q
how to loop a sequence in reverse?
A
for i in reversed(range(1,10):
5
Q
how to loop a sequence in sorted order?
A
for i in sorted(set([‘apple’,’orange’]))