[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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[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

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[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, 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 rep...@bugs.python.org
http://bugs.python.org/issue21978
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[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 sequence behavior is to build a list:

   s = list(od)
   s = list(od.values())
   s = list(od.items())

--
assignee:  - rhettinger
nosy: +rhettinger
priority: normal - low
type:  - enhancement

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21978
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[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 and OrderedDicts don't support 
reasonable ways to index by position.   Guido essentially decided on the 
current behavior this when he decided to do away the Python's dict.items() 
being a list and replacing it with a mapping view.  See PEP 3016 for his 
rationale and the related discussion.

--
resolution:  - rejected
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21978
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com