I don’t know about cleaner, but there’s another alternative:
for (op, code) in zip(s[0::2], s[1::2]):
print op, code
A no-copy version:
from itertools import izip, islice
for (op, code) in izip(islice(s, 0, None, 2), islice(s, 1, None, 2)):
print op, code
More Related Contents:
- What is the fastest and pythonic way to generate a list [(0,0), (0,1), (0,2)…(0,100)]? [closed]
- List Element without iteration
- Python Error with iteration, for loop
- How to remove items from a list while iterating?
- What exactly are iterator, iterable, and iteration?
- Does pandas iterrows have performance issues?
- Iterating through a range of dates in Python
- Iterating on a file doesn’t work the second time
- Iterate over object attributes in python [duplicate]
- What is the perfect counterpart in Python for “while not EOF”
- What are iterator, iterable, and iteration?
- Grouping / clustering numbers in Python
- How to loop over grouped Pandas dataframe?
- Is there a better way to iterate over two lists, getting one element from each list for each iteration? [duplicate]
- Modify a list while iterating
- Intersecting two dictionaries
- What exactly is Python’s iterator protocol?
- How do I loop through a list by twos? [duplicate]
- Is generator.next() visible in Python 3?
- Iterate over all combinations of values in multiple lists in Python [duplicate]
- How to iterate through a list of dictionaries in Jinja template?
- Iteration over list slices
- Converting for loops to while loops in python
- “For” loop first iteration
- Spark iteration time increasing exponentially when using join
- How can I collect the results of a repeated calculation in a list, dictionary etc. (make a copy of a list with each element modified)?
- What is the meaning of list[:] in this code? [duplicate]
- Customizing unittest.mock.mock_open for iteration
- range(len(list)) or enumerate(list)? [duplicate]
- Do python’s variable length arguments (*args) expand a generator at function call time?