[issue21978] Support index access on OrderedDict views (e.g. o.keys()[7])

2016-12-08 Thread INADA Naoki
INADA Naoki added the comment: While dict is ordered, it doesn't support O(1) random access by index. -- nosy: +inada.naoki ___ Python tracker ___

[issue21978] Support index access on OrderedDict views (e.g. o.keys()[7])

2016-12-07 Thread Ulrich Petri
Ulrich Petri added the comment: Should this maybe reconsidered now that dicts are ordered by default? Having to explain why list is needed in list(some_ordered_dict.values())[0] is a constant thorn in my side when dealing with people new to Python. -- nosy: +ulope

[issue21978] Support index access on OrderedDict views (e.g. o.keys()[7])

2014-07-14 Thread Ram Rachum
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,

[issue21978] Support index access on OrderedDict views (e.g. o.keys()[7])

2014-07-14 Thread Raymond Hettinger
Raymond Hettinger added the comment: I'm not sure this would make sense given that the ordered dict itself isn't indexable, given that keys/values/items on regular dicts aren't indexable, and given that keys/items views are set-like rather than sequence-like. The one obvious way to get

[issue21978] Support index access on OrderedDict views (e.g. o.keys()[7])

2014-07-14 Thread Raymond Hettinger
Raymond Hettinger added the comment: Closing this. The premise is flawed. Guido designed mapping views to be a pass-through to the underlying mapping. As such, they would only have sequence behavior if the underlying mapping had sequence behavior. The implementation of both regular dicts