On Sat, Oct 16, 2021 at 10:56:07AM -0400, David Mertz, Ph.D. wrote:
> POn Sat, Oct 16, 2021, 10:10 AM Erik Demaine
>
> > (*it1, *it2, *it3) # tuple with the concatenation of three iterables
> > [*it1, *it2, *it3] # list with the concatenation of three iterables
> > {*it1, *it2, *it3} # set with the union of three iterables
> > {**dict1, **dict2, **dict3} # dict with the combination of three dicts
>
>
> I'm +0 on the last three of these.
>
> But the first one is much more suggestive of a generator comprehension. I
> would want/expect it to be equivalent to itertools.chain(), not create a
> tuple.
Too late.
>>> (*"abc", *"def", *"ghi")
('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i')
I think you may have missed that those examples of unpacking are
existing functionality, not the proposal. The proposal is to allow
unpacking in *comprehensions*.
# not currently permitted
[*s for s in ["abc", "def", "ghi"]]
> Moreover, it is an anti-pattern to create large and indefinite sized
> tuples,
Is it? In what way?
As far as I understand it, a large tuple is more memory efficient than a
large list (it has no over-allocated space). The only issue that I know
of is that if the length of the tuple is not known ahead of time, the
interpreter may have to grow, or shrink, the underlying array before
completing the tuple construction.
--
Steve
_______________________________________________
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/NY32M7DHURO75YXAFQYSYUEM6ENNAV4D/
Code of Conduct: http://python.org/psf/codeofconduct/