Skipping to Next item in Dictionary
dictionary, python, python-2.7
Solution
Use `continue`:
for key, value in mydict.iteritems():
if key == 'skipthis':
continue
Also see:
- Are `break` and `continue` bad programming practices?
Problem
When iterating through a dictionary, I want to skip an item if it has a particular key. I tried something like `mydict.next()`, but I got an error message `'dict' object has no attribute 'next'` ``` for key, value in mydict.iteritems(): if key == 'skipthis': mydict.next() # for others do some complicated process ``` I am using Python 2.7 if that matters.