On Wed, Jul 29, 2020 at 7:23 AM Wes Turner <wes.turner@gmail.com> wrote:
.iloc[] is the Pandas function for accessing by integer-location:
 https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.iloc.html

I'm not sure I quite get the analogy here, but ...

>>> odict.iloc[3]

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()[3] IS a bit klunkier than odict.iloc[3]

(Side note: why ARE the views provided by methods, rather than properties? But I digress ...)
 
>>> odict[3:4]

that would be possible.

What does this do? Confusing to a beginner:

>>> odict[3,]

no more confusing than it is for Sequences, is it?

In [4]: 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.

-CHB

--
Christopher Barker, PhD

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython