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

Peter Abel p-abel at t-online.de
Tue Jan 14 02:40:18 EST 2003


jbperez808 at yahoo.com (Jonathan P.) wrote in message news:<f57664b9.0301131444.26ca3b43 at posting.google.com>...
> s=''
> for i in range(1,255):
>   s+=chr(i)
> 
> has horrible performance (primarily due to string
> immutability I think).  Is there a function to do
> the ff. instead:
> 
> x=range(1,255)
> list2str(x)
> 
> and have x become a string?

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




More information about the Python-list mailing list