fast way of turning a list of integers<256 into a string

Mike C. Fletcher mcfletch at
Tue Jan 14 10:02:09 CET 2003

Well, if we all get an entry free, here's my primary entry...

 >>> d = "".join( map(str,myints) )

Would be my entry for small arrays, it's straightforward and 
idio(t)matic :) .

 >>> struct.pack( ">"*len(myints), *myints )

is slightly faster than the "".join version for 100,000 items on my 
machine (there's fewer individually-managed objects created), but it's 
less idiomatic IMO, so I won't put it in as my entry ;) .  If there are 
large arrays involved you should obviously import Numeric and do it 
right :) .


Peter Abel wrote:

>jbperez808 at (Jonathan P.) wrote in message news:<f57664b9.0301131444.26ca3b43 at>...

>everybody has one shot free.
>Here is mine one:
>>>>text=reduce(lambda x,y:x+chr(y),range(32,128,1),'')
>' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f'
  Mike C. Fletcher
  Designer, VR Plumber, Coder

More information about the Python-list mailing list