Are you suggesting that dict views would become subscriptable?
In : %doctest_mode Exception reporting mode: Plain Doctest mode is: ON
x = dict(a=2, b=3, c=4) x.items()
Traceback (most recent call last): File "<ipython-input-5-519a9a9c5ae6>", line 1, in <module> x.items() TypeError: 'dict_items' object is not subscriptable
On Thu, Jul 30, 2020, 12:05 PM Christopher Barker email@example.com wrote:
On Wed, Jul 29, 2020 at 7:23 AM Wes Turner firstname.lastname@example.org wrote:
.iloc is the Pandas function for accessing by integer-location:
I'm not sure I quite get the analogy here, but ...
Would this be the only way to access only item 4 from an odict of length greater than 4 with slice notation for dict views generated from selection by integer-location?
are suggesting that we add another attribute to dicts to provide "index" access? I'm not sure the advantage of that, as we already have the dict views, so I guess it's nice not to have the type the parentheses:
odict.items() IS a bit klunkier than odict.iloc
(Side note: why ARE the views provided by methods, rather than properties? But I digress ...)
that would be possible.
What does this do? Confusing to a beginner:
no more confusing than it is for Sequences, is it?
In : l[3,]
TypeError Traceback (most recent call last) <ipython-input-4-ca8ec5ca5475> in <module> ----> 1 l[3,]
TypeError: list indices must be integers or slices, not tuple
But yes, if we allowed dicts to be indexable with slices, they still couldn't be indexed by single indexes (unless that value happened to be a key) so there would be no way to get a single item by index, as a length-1 slice would presumably return a dict with one item.
So yeah, if indexing, slicing were to happen, it would have to be in the views.
But this does bring up that there are a lot of places where slice notation could be used outside of  -- and that would be handy for use cases like pandas, even if not for dicts.
-- Christopher Barker, PhD
Python Language Consulting
- Scientific Software Development
- Desktop GUI and Web Development
- wxPython, numpy, scipy, Cython