Crawling Python

Joshua Rosen rozzin at geekspace.com
Fri Jun 25 11:02:08 EDT 1999


Michael Haggerty wrote:
> >>> import string
> >>> s = []
> >>> for i in d.keys():
> >>>   s.append(d[i])
> >>> s = string.join(s, '')
> 
> then you get exactly the same result in O(n) time, because s.append()
> doesn't have to copy each time.  For large n the second algorithm will
> beat the first one every time, by an increasingly huge margin.

How about...

from array import array
s = array('c')
for e in d.values():
s.fromstring(e)
s = s.tostring()

...?





More information about the Python-list mailing list