lists, performance..

gabor gabor at realtime.sk
Thu Oct 31 09:34:29 EST 2002


On Thu, 2002-10-31 at 15:26, holger krekel wrote:
> the fastest method i know for your problem is:
> 
> >>> a,b=[1,2,3],[2,3,4]
> >>> n=[]
> >>> filter(n.append, a)
> []
> >>> filter(n.append, b)
> []
> >>> n
> [1, 2, 3, 4, 5, 6]
> >>>
> 
> It's very fast because 'list.append' and 'filter' both have
> c-level implementations.
>   
> > but maybe this is too slow.. or isn't? ideally i'd like to have
> > something like reserve in c++....
> > so let's say i have a list which len() is 30. now i want to insert
> > 20elements... wouldn't it be faster to somehow resize the list directly
> > to 50, and then add the elements?
> > i'm worried about how many times would the list resize itself to be able
> > to contain the additional 20elements if i would add them one-by-one
> 
> time the above solution and see if it's fast enough for you.

btw. is there a timing function in python?
like 'time' in unix..

thanks,
gabor
-- 
listening to Paul van Dyk, BT, Gargano, Corsten, etc. - Nyman Essential
Trance
gpg key at www.keyserver.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/python-list/attachments/20021031/10d4eca8/attachment.sig>


More information about the Python-list mailing list