On Thu, Aug 27, 2020 at 10:24 AM David Mertz <[email protected]> wrote:
> On Thu, Aug 27, 2020, 1:15 PM Christopher Barker
>
>> I agree -- this is very much a feature for third party packages -- or
>> *maybe* some future stdlib class, but the builtins are fine as they are.
>>
>> In fact, I don't think there's a single use of a tuple of indexes
>> (meaning something other than an arbitrary single object) in the stdlib is
>> there? I know I've only used that in numpy.
>>
>
> I don't know whether it is in the stdlib, but I sometimes use tuples as
> dict keys. E.g.
>
> mydict[('mertz', 'david')] = 3.1415
>
Exactly -- that's what I meant by "an arbitrary single object" -- as far as
dict is concerned, that's simply a hashable object. period, the dict code
doesn't parse it out in any way at all.
> Even though I could omit them, I'd almost surely use the parens for that.
> And more likely it would be:
>
Me too -- I always use the parens -- it never even dawned on me until this
thread that I could omit them :-)
But numpy on the other hand, when you pass it:
arr[i, j]
it specifically parses out that tuple, and uses i for the zeroth axis, and
j for the first axis -- it is very much NOT an arbitrary tuple. And while
you could do:
indexes = (i, j)
arr(indexes)
That is very rarely done, because conceptually, you are passing two
indexes, not one object.
I've used Python and numpy (before that Numeric and numarray) for 20 years,
and I only recently understood that [] always took only a single
expression, and that the ability to pass multiple indexes was really only
because you can make a tuple without parens, so that i, j is the same as
(i, j).
-CHB
--
Christopher Barker, PhD
Python Language Consulting
- Teaching
- Scientific Software Development
- Desktop GUI and Web Development
- wxPython, numpy, scipy, Cython
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/RWC77OGJCY7ZC2QBSZ4UGWPLGA6KBQUC/
Code of Conduct: http://python.org/psf/codeofconduct/