<div dir="ltr">I think you've got it backwards -- if you send the patch the idea *may* be accepted. You ought to at least show us the docs for your proposed factory, it's a little murky from your example.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 8, 2017 at 6:34 AM, Sergey Fedoseev <span dir="ltr"><<a href="mailto:fedoseev.sergey@gmail.com" target="_blank">fedoseev.sergey@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
Sometimes you may need to create many dicts with the same keys, but different<br>
values. For example, if you want to return data from DB as dicts.<br>
<br>
I think that special type could be added to solve this task more effectively.<br>
I created proof of concept for this and here's benchmarks:<br>
<br>
# currently the fastest way to do it AFAIK<br>
$ ./python -m timeit -s "nkeys = 5; nrows = 1000; rows = [(i,)*nkeys<br>
for i in range(nrows)]; enumerated = list(enumerate(range(nkeys)))"<br>
"for row in rows: {key: row[i] for i, key in enumerated}"<br>
500 loops, best of 5: 645 usec per loop<br>
<br>
$ ./python -m timeit -s "nkeys = 5; nrows = 1000; rows = [(i,)*nkeys<br>
for i in range(nrows)]; factory = dict.factory(*range(nkeys)); from<br>
itertools import starmap" "for d in starmap(factory, rows): d"<br>
5000 loops, best of 5: 81.1 usec per loop<br>
<br>
I'd like to write a patch if this idea will be accepted.<br>
______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
</blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div>