Skip to content

Instantly share code, notes, and snippets.

@capttwinky
Created August 28, 2014 20:22
Show Gist options
  • Save capttwinky/7bcb49f5ba8a5a85a4af to your computer and use it in GitHub Desktop.
Save capttwinky/7bcb49f5ba8a5a85a4af to your computer and use it in GitHub Desktop.
None safe iterators
import collections
def strict_iterator(iterable):
if not isinstance(iterable, collections.Iterable):
raise StopIteration
else:
for i in iterable:
yield i
def safe_iterator(iterable):
try:
for i in iterable:
yield i
except TypeError:
raise StopIteration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment