On Fri, Jul 17, 2020 at 11:49 AM Jonathan Fine <[email protected]> wrote:
> I am able today to respond to one question. Ricky asked if
> >>> key_object = K(a=1, b=2) # where K is some new key object type
> >>> d1 = {key_object: 3}
> >>> d2 = {}
> >>> d2[a=1, b=2] = 3
> >>> assert d1==d2
> was what I had in mind. The answer is YES, and in some ways better
> expressed. (And the new key object type is introduced only if necessary for
> the desired user experience.)
>
Maybe I’m being dense here, but I need more explainatikn of what this “key
object” is, how it works, or what its purpose is.
The use of dict literals makes the role of the key_object even clearer.
>
Not to me :-(
For clarity, when we write
> >>> d[1, 2, 3] = 4
> the associated key_object, for backwards compatibility, must be (1, 2, 3),
> which is a tuple.
>
Yes, and tuples are perfectly valid dict keys, so nothing new here.
>
> Again for clarity, in today's Python the statements
> >>> d[1, 2, 3] = 4
> >>> d[(1, 2, 3)] = 4
> are equivalent. I willingly accept this as a constraint. In my own mind, I
> require it.
>
Which is due to tuples being created by the commas ...
So what would the “key object” be I the proposed case:
d2[a=1, b=2]
A namedtuple? Or namedtuple-like object?
The other trick here is that currently in indexes, the comma currently
creates a tuple in the general case, for instance:
Something[1:2, 3:4] creates a tuple with two slice objects in it. (Heavily
used by numpy.
So if d2[a=1, b=2] creates single object (which should not be
dict-specific, so not a key per se), how would you created a tuple of more
than one such object? Maybe:
Something[(a=5, b=6), (c=7, d=8)]
Anyway, I think a prototype is in order.
-CHB
Once again, thank you all, and I'll say more tomorrow (about 18 hours from
> now).
> --
> Jonathan
>
>
> _______________________________________________
> 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/UFXWGFAUUQGMA7DBNYAK53THIWQOL632/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
--
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/MPAGYF33Q3JA4JTEYAHJCGQ6LWPIKN2L/
Code of Conduct: http://python.org/psf/codeofconduct/