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
Related Contents:
- What is the use of iter in python?
- 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
- Are for-loops in pandas really bad? When should I care?
- Is there a way in Pandas to use previous row value in dataframe.apply when previous value is also calculated in the apply?
- Iterating each character in a string using Python
- Loop that also accesses previous and next values
- What are iterator, iterable, and iteration?
- Iterate over object attributes in python [duplicate]
- What is the perfect counterpart in Python for “while not EOF”
- recursive iteration through nested json for specific key in python
- 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 recursively find specific key in nested JSON?
- Spark iteration time increasing exponentially when using join
- Python using enumerate inside list comprehension
- Python: Adding element to list while iterating
- What is the meaning of list[:] in this code? [duplicate]
- Iteration over list slices
- Converting a list of tuples into a dict
- How to iterate through a list of dictionaries in Jinja template?
- How can I collect the results of a repeated calculation in a list, dictionary etc. (or make a copy of a list with each element modified)?
- How to loop backwards in python? [duplicate]
- How to transform string of space-separated key,value pairs of unique words into a dict
- “For” loop first iteration
- Converting for loops to while loops in python
- Set iteration order varies from run to run
- How do I get the filename without the extension from a path in Python?
- How to extract the substring between two markers?
- How to get multiline input from user [duplicate]
- Numpy where function multiple conditions
- How can I build multiple submit buttons django form?
- Pandas index column title or name
- Why is my PyGame Sprite, in a Group, not drawn – AttributeError: ‘Group’ object has no attribute ‘blitme’
- Retrieve top n in each group of a DataFrame in pyspark
- Python Code Obfuscation [closed]
- Is there a build-in function to do skeletonization?
- How to convert a time string to seconds?
- How can I compare two ordered lists in python?
- How to use python mysqldb to insert many rows at once