summaryrefslogtreecommitdiff
path: root/six.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2011-09-16 10:56:16 -0400
committerBenjamin Peterson <benjamin@python.org>2011-09-16 10:56:16 -0400
commite9c41d235dc60ea07fa83d59c9df3c100661eaec (patch)
tree150e356dbf9fd68eb4f7656e9c93244f61b3255f /six.py
parentbcb49f3d5ddc4922ce9df726836cc1689c64e244 (diff)
downloadsix-e9c41d235dc60ea07fa83d59c9df3c100661eaec.tar.gz
add wrappers for iterating over keys/values/items of a dictionary
Diffstat (limited to 'six.py')
-rw-r--r--six.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/six.py b/six.py
index 26d066d..2607931 100644
--- a/six.py
+++ b/six.py
@@ -184,6 +184,10 @@ if PY3:
_func_code = "__code__"
_func_defaults = "__defaults__"
+
+ _iterkeys = "keys"
+ _itervalues = "values"
+ _iteritems = "items"
else:
_meth_func = "im_func"
_meth_self = "im_self"
@@ -191,6 +195,10 @@ else:
_func_code = "func_code"
_func_defaults = "func_defaults"
+ _iterkeys = "iterkeys"
+ _itervalues = "itervalues"
+ _iteritems = "iteritems"
+
if PY3:
def get_unbound_function(unbound):
@@ -220,6 +228,19 @@ get_function_code = operator.attrgetter(_func_code)
get_function_defaults = operator.attrgetter(_func_defaults)
+def iterkeys(d):
+ """Return an iterator over the keys of a dictionary."""
+ return getattr(d, _iterkeys)()
+
+def itervalues(d):
+ """Return an iterator over the values of a dictionary."""
+ return getattr(d, _itervalues)()
+
+def iteritems(d):
+ """Return an iterator over the (key, value) pairs of a dictionary."""
+ return getattr(d, _iteritems)()
+
+
if PY3:
def b(s):
return s.encode("latin-1")