Useful Python looping techniques
26th September 2007
These are all excerpts from the Python documentation.
To synchronously and simultaneously loop over two sequences:
- questions = ['name', 'quest', 'favourite colour']
- answers = ['Lancelot', 'the holy grail', 'blue']
- for q, a in zip(questions, answers):
- print 'What is your %s? It is %s.' % (q, a)
To loop over a sequence with both key and value:
Read the rest of this entry »
Posted in Programming, Python | No Comments »
