[issue21978] Support index access on OrderedDict views (e.g. o.keys()[7])
Ram Rachum
report at bugs.python.org
Mon Jul 14 11:15:03 CEST 2014
New submission from Ram Rachum:
Implement `__getitem__` on `OrdredDict.keys`, `OrdredDict.values` and `OrdredDict.items`, so the following code snippet wouldn't error:
>>> from collections import OrderedDict
>>> o = OrderedDict(((1, 2), (3, 4), (5, 6)))
>>> o
OrderedDict([(1, 2), (3, 4), (5, 6)])
>>> o.keys()
KeysView(OrderedDict([(1, 2), (3, 4), (5, 6)]))
>>> o.keys()[0]
Traceback (most recent call last):
File "<string>", line 1, in <fragment>
builtins.TypeError: 'KeysView' object does not support indexing
>>> o.values()[0]
Traceback (most recent call last):
File "<string>", line 1, in <fragment>
builtins.TypeError: 'ValuesView' object does not support indexing
>>> o.items()[0]
Traceback (most recent call last):
File "<string>", line 1, in <fragment>
builtins.TypeError: 'ItemsView' object does not support indexing
----------
components: Library (Lib)
messages: 223006
nosy: cool-RR
priority: normal
severity: normal
status: open
title: Support index access on OrderedDict views (e.g. o.keys()[7])
versions: Python 3.5
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21978>
_______________________________________
More information about the Python-bugs-list
mailing list