fast way of turning a list of integers<256 into a string
Andrew Bennetts
andrew-pythonlist at puzzling.org
Mon Jan 13 18:07:21 EST 2003
On Mon, Jan 13, 2003 at 02:44:51PM -0800, Jonathan P. wrote:
> 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)
How about this?
>>> x = range(65,91)
>>> ''.join(map(chr, x))
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
-Andrew.
More information about the Python-list
mailing list