Skip to content

Instantly share code, notes, and snippets.

@jriddy
Created December 16, 2015 22:40
Show Gist options
  • Save jriddy/7b1098e0fbda52ee81f8 to your computer and use it in GitHub Desktop.
Save jriddy/7b1098e0fbda52ee81f8 to your computer and use it in GitHub Desktop.
def iterable_nonstring(x):
"""Determines whether an object is iterable and not a string or unicode.
This is incorrect for python 3.
"""
return hasattr(x, '__iter__')
def iterable(x):
"""Determines whether an object can be iterated over.
The `or` is unneccesary for python 3.
"""
return iterable_nonstring(x) or isinstance(x, basestring)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment