Re: [Python-ideas] namedtuple with ordereddict

2017-07-19 Thread Terry Reedy
On 7/19/2017 12:10 PM, Giampaolo Rodola' wrote: On Wed, Jul 19, 2017 at 5:20 PM, Tim Peters > wrote: [Giampaolo Rodola' mailto:g.rod...@gmail.com>>] > Still much slower (-4.3x) than plain tuples though: > > $ python3.7 -m timeit -s "import collect

Re: [Python-ideas] namedtuple with ordereddict

2017-07-19 Thread Alexander Belopolsky
On Wed, Jul 19, 2017 at 12:10 PM, Giampaolo Rodola' wrote: > Should have been something like this instead: > > $ python3.7 -m timeit -s "import collections; Point = > collections.namedtuple('Point', ('x', 'y')); x = [5, 1]" "Point(*x)" > 100 loops, best of 5: 311 nsec per loop > > $ python3.

Re: [Python-ideas] namedtuple with ordereddict

2017-07-19 Thread Giampaolo Rodola'
On Wed, Jul 19, 2017 at 5:20 PM, Tim Peters wrote: > [Giampaolo Rodola' ] > > Still much slower (-4.3x) than plain tuples though: > > > > $ python3.7 -m timeit -s "import collections; Point => > collections.namedtuple('Point', ('x', 'y'));" "Point(5, 11)" > > 100 loops, best of 5: 313 nsec pe

Re: [Python-ideas] namedtuple with ordereddict

2017-07-19 Thread Tim Peters
[Giampaolo Rodola' ] > Still much slower (-4.3x) than plain tuples though: > > $ python3.7 -m timeit -s "import collections; Point => > collections.namedtuple('Point', ('x', 'y'));" "Point(5, 11)" > 100 loops, best of 5: 313 nsec per loop > > $ python3.7 -m timeit "tuple((5, 11))" > 500 lo

Re: [Python-ideas] namedtuple with ordereddict

2017-07-19 Thread Giampaolo Rodola'
On Wed, Jul 19, 2017 at 3:27 AM, Steven D'Aprano wrote: > On Tue, Jul 18, 2017 at 06:16:26PM -0400, Jim J. Jewett wrote: > > Then constructing a specific instance from the arguments used to > > create it could be as simple as keeping a reference to the temporary > > created to pass those argument

Re: [Python-ideas] namedtuple with ordereddict

2017-07-18 Thread Serhiy Storchaka
19.07.17 01:33, Greg Ewing пише: Jim J. Jewett wrote: is there any reason not to simply define it as a view on a dict, or at least as a limited proxy to one? Some valuable characteristics of namedtuples as they are now: * Instances are very lightweight * Access by index is fast * Can be used

Re: [Python-ideas] namedtuple with ordereddict

2017-07-18 Thread Steven D'Aprano
On Tue, Jul 18, 2017 at 06:16:26PM -0400, Jim J. Jewett wrote: > Given that > > (1) dicts now always pay the price for ordering > (2) namedtuple is being accelerated > > is there any reason not to simply define it as a view on a dict, or at > least as a limited proxy to one? Tuples are much more

Re: [Python-ideas] namedtuple with ordereddict

2017-07-18 Thread Greg Ewing
Jim J. Jewett wrote: is there any reason not to simply define it as a view on a dict, or at least as a limited proxy to one? Some valuable characteristics of namedtuples as they are now: * Instances are very lightweight * Access by index is fast * Can be used as a dict key All of those would

[Python-ideas] namedtuple with ordereddict

2017-07-18 Thread Jim J. Jewett
Given that (1) dicts now always pay the price for ordering (2) namedtuple is being accelerated is there any reason not to simply define it as a view on a dict, or at least as a limited proxy to one? Then constructing a specific instance from the arguments used to create it could be as simple as