Figured I would add my own [7]. I know the example prompt might seem a bit specific, but it can come in really handy sometimes (for example, iterating through get parameters). Always a fan of idiomatic and one-liner python.
I should mention that I ended up using the fourth version (seemingly the slowest) but it is actually the fastest depending on your input -- as the length of the elements gets larger, the fourth method tends to vastly outperform the others.
- Idiomatic way to take groups of n items from a list in Python? [2]
- Python “Every Other Element” Idiom [3]
- Iterate an iterator by chunks (of n) in Python? [4]
- How do you split a list into evenly sized chunks in Python? [5]
[1]: http://stackoverflow.com/questions/434287/what-is-the-most-p...
[2]: http://stackoverflow.com/questions/2461484/idiomatic-way-to-...
[3]: http://stackoverflow.com/questions/2631189/python-every-othe...
[4]: http://stackoverflow.com/questions/8991506/iterate-an-iterat...
[5]: http://stackoverflow.com/questions/312443/how-do-you-split-a...
[6]: http://docs.python.org/3/library/itertools.html#itertools-re...