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 <[email protected]>
<http://bugs.python.org/issue21978>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com