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

Andrew Thompson andrew.thompson at ashecastle.com
Tue Jan 14 03:52:29 EST 2003


I would try something along the lines of

import array
array.array('B',range(1,255)).tostring()

-----Original Message-----
From: python-list-admin at python.org [mailto:python-list-admin at python.org]
On Behalf Of Peter Abel
Sent: 14 January 2003 07:40
To: python-list at python.org
Subject: Re: fast way of turning a list of integers<256 into a string


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[\\]^_`abcdef
ghijklmnopqrstuvwxyz{|}~\x7f'
>>> 
regards
Peter
-- 
http://mail.python.org/mailman/listinfo/python-list






More information about the Python-list mailing list