[Python-Dev] Proposal: dict.with_values(iterable)
On Fri, Apr 12, 2019 at 8:35 AM Serhiy Storchaka <storchaka at gmail.com>
> 12.04.19 16:44, Inada Naoki ????:
> > When creating many dicts with same keys, dict need to
> > lookup internal hash table while inserting each keys.
> > It is costful operation. If we can reuse existing keys of dict,
> > we can skip this inserting cost.
> > Additionally, we have "Key-Sharing Dictionary (PEP 412)".
> > When all keys are string, many dict can share one key.
> > It reduces memory consumption.
> It looks contrary to simplification made in Python 3 when we get rid of
> some more efficient lists in favor of more general iterators.
> If this is a common case
I think that "if" is my big sticking point. I don't think I've ever had a
need for this and the zip() solution was what I originally thought of when
I realized what the method was meant to do (which wasn't obvious to me
This doesn't strike me as needing an optimization through a dedicated
> we can add an invisible optimization for
> dict(zip(keys, values)), especially if keys is a key-sharing dictionary.
> This will benefit all users without the need to rewrite the code to use
> the new special method.
> The interface of dict is already overloaded. It contains many methods
> which most users use rarely (and therefore which are not kept in the
> working set of memory).
> Python-Dev mailing list
> Python-Dev at python.org
-------------- next part --------------
An HTML attachment was scrubbed...