[issue33462] reversible dict

Rémi Lapeyre report at bugs.python.org
Wed May 23 12:18:18 EDT 2018


Rémi Lapeyre <remi.lapeyre at henki.fr> added the comment:

I updated the pull request, now reversed work on the dict and dict views:

➜  cpython git:(master) ./python.exe 
Python 3.8.0a0 (heads/master-dirty:128576b88c, May 23 2018, 16:33:46) 
[Clang 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> d = dict(a=1, b=2)
>>> list(reversed(d))
['b', 'a']
>>> list(reversed(d.keys()))
['b', 'a']
>>> list(reversed(d.values()))
[2, 1]
>>> list(reversed(d.items()))
[('b', 2), ('a', 1)]

reversed on dict and dict views is not symmetric and applying twice will  raise TypeError which is also the behavior on list. I'm not sure why this behavior has been chosen but it's coherent.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33462>
_______________________________________


More information about the Python-bugs-list mailing list