diff options
author | Benjamin Peterson <benjamin@python.org> | 2011-09-16 10:56:16 -0400 |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2011-09-16 10:56:16 -0400 |
commit | e9c41d235dc60ea07fa83d59c9df3c100661eaec (patch) | |
tree | 150e356dbf9fd68eb4f7656e9c93244f61b3255f /six.py | |
parent | bcb49f3d5ddc4922ce9df726836cc1689c64e244 (diff) | |
download | six-e9c41d235dc60ea07fa83d59c9df3c100661eaec.tar.gz |
add wrappers for iterating over keys/values/items of a dictionary
Diffstat (limited to 'six.py')
-rw-r--r-- | six.py | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -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") |