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.
On Fri, Sep 8, 2017 at 6:34 AM, Sergey Fedoseev <fedoseev.ser...@gmail.com> wrote: > Hi all, > > Sometimes you may need to create many dicts with the same keys, but > different > values. For example, if you want to return data from DB as dicts. > > I think that special type could be added to solve this task more > effectively. > I created proof of concept for this and here's benchmarks: > > # currently the fastest way to do it AFAIK > $ ./python -m timeit -s "nkeys = 5; nrows = 1000; rows = [(i,)*nkeys > for i in range(nrows)]; enumerated = list(enumerate(range(nkeys)))" > "for row in rows: {key: row[i] for i, key in enumerated}" > 500 loops, best of 5: 645 usec per loop > > $ ./python -m timeit -s "nkeys = 5; nrows = 1000; rows = [(i,)*nkeys > for i in range(nrows)]; factory = dict.factory(*range(nkeys)); from > itertools import starmap" "for d in starmap(factory, rows): d" > 5000 loops, best of 5: 81.1 usec per loop > > I'd like to write a patch if this idea will be accepted. > _______________________________________________ > Python-ideas mailing list > Python-ideas@python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ > -- --Guido van Rossum (python.org/~guido)
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/