Skip to content

Instantly share code, notes, and snippets.

@rwhitt2049
Created November 12, 2013 22:22
Show Gist options
  • Select an option

  • Save rwhitt2049/7439882 to your computer and use it in GitHub Desktop.

Select an option

Save rwhitt2049/7439882 to your computer and use it in GitHub Desktop.
backwards compatibility for python 2/3 dictionary calls
def iterkeys(d):
"""Python 2/3 compatibility function for dict.iterkeys()"""
if __python_version_major >= 3:
return d.keys()
else:
return d.iterkeys()
def itervalues(d):
"""Python 2/3 compatibility function for dict.itervalues()"""
if __python_version_major >= 3:
return d.values()
else:
return d.itervalues()
def iteritems(d):
"""Python 2/3 compatibility function for dict.iteritems()"""
if __python_version_major >= 3:
return d.items()
else:
return d.iteritems()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment