[Python-ideas] namedtuple literals [Was: RE a new namedtuple]
Giampaolo Rodola'
g.rodola at gmail.com
Tue Jul 25 17:00:00 EDT 2017
On Thu, Jul 20, 2017 at 3:35 AM, Alexander Belopolsky <
alexander.belopolsky at gmail.com> wrote:
> On Wed, Jul 19, 2017 at 9:08 PM, Guido van Rossum <guido at python.org>
> wrote:
> > The proposal in your email seems incomplete
>
> The proposal does not say anything about type((x=1, y=2)). I assume
> it will be the same as the type currently returned by namedtuple(?, 'x
> y'), but will these types be cached?
I suppose that the type should be immutable at least as long as field names
are the same, and the cache will occur on creation, in order to retain the
0 memory footprint.
Will type((x=1, y=2)) is type((x=3, y=4)) be True?.
Yes.
> Maybe type((x=1, y=2))(values) will work?
>
It's supposed to behave like a tuple or any other primitive type (list,
set, etc.), so yes.
> Regarding that spec, I think there's something missing: given a list (or
> tuple!) of values, how do you turn it into an 'ntuple'?
As already suggested, it probably makes sense to just reuse the dict syntax:
>>> dict([('a', 1), ('b', 2)])
{'a': 1, 'b': 2}
>>> ntuple([('a', 1), ('b', 2)])
(a=1, b=2)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170725/9dc29644/attachment-0001.html>
More information about the Python-ideas
mailing list