On Thu, Aug 27, 2020 at 1:29 PM 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
>
> Even though I could omit them, I'd almost surely use the parens for that.
> And more likely it would be:
>
> name = ('mertz', 'david')
> mydict[name] = 3.1415
>
> Conceptually, an "immutable collection" serves a different purpose than "a
> collection of axes", even if they work then same under the hood.
>
What about something like this:
class Name(NamedTuple):
first: str
last: str
d = NamedKeyDict(Named)
d[first='david', last='mertz'] = 1_000_000 # dollars
---
Ricky.
"I've never met a Kentucky man who wasn't either thinking about going home
or actually going home." - Happy Chandler
_______________________________________________
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/42P4KZLB35EFC24HR66U5H3QBN4RK7ST/
Code of Conduct: http://python.org/psf/codeofconduct/