List append vs add

Thomas Wouters thomas at xs4all.net
Fri May 25 16:48:16 CEST 2001


On Fri, May 25, 2001 at 02:04:04PM +0000, Fredrik Lundh wrote:
> Thomas Wouters wrote:
> > > > list.append('fred')
> > > >
> > > > compared with,
> > > >
> > > > list+=['fred']
> >
> > > There is no difference in result.  The former strikes me as clearer,
> > > and might well be quicker.
> >
> > It is quicker, but not by much. The += version skips the method lookup,
> > method call, and argument parsing that the .append version has to go
> > through, at the cost of a function-lookup in the type slot.

> on the other hand, the += solution has to create a temporary
> one-element list for each append.

You're right. I was thinking of 'extend', not 'append'. 

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list