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

Mike C. Fletcher mcfletch at rogers.com
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 :) .

Enjoy,
Mike

Peter Abel wrote:

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

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








More information about the Python-list mailing list