[Python-ideas] crazy ideas

Josiah Carlson jcarlson at uci.edu
Tue May 22 23:29:51 CEST 2007


"Ian D. Bollinger" <ian.bollinger at gmail.com> wrote:
> 
> Josiah Carlson wrote:
> > In terms of having a syntax for deques, I honestly don't see the problem
> > with deque([a,b,c]).  It has all of 6 more characters to type than your
> > proposed d{a,b,c} syntax, without cluttering up the language with yet
> > another bit of syntax that can be replaced with a 2 line function...
> >
> > def d(*args):
> >     return deque(args)
> >   
> But what about all the memory overhead of constructing the list argument?!
> (I turn off my car radio to save gas.)

Even with syntax, the content of the deque needs to be loaded on the
stack for either a 'stack to deque' operation (like the equivalent stack
to list or stack to tuple operations), or a stack to list to deque
operation.  And unless you are creating huge deques in-line, starting
from a list won't incur any significant memory overhead as short lists 
(0, 4, 8, 16, etc.) are usually handled by Python's small memory
allocator.

If you really want to prove it to yourself that it doesn't matter, try
benchmarking the difference between...

    d = deque(())
    d = deque([])

    d = deque((1,2,3,4,5,6,7,8,9,10))
    d = deque([1,2,3,4,5,6,7,8,9,10])


 - Josiah




More information about the Python-ideas mailing list