numbers to string

Travis E. Oliphant oliphant.travis at ieee.org
Wed Oct 25 02:38:21 EDT 2006


David Isaac wrote:
>>>> y
> [116, 114, 121, 32, 116, 104, 105, 115]
>>>> z=''.join(chr(yi) for yi in y)
>>>> z
> 'try this'
> 
> What is an efficient way to do this if y is much longer?
> (A numpy solution is fine.)

Here's another numpy solution just for fun:

import numpy
z = numpy.array(y,dtype='u1').view('S%d' % len(y))[0]


-Travis




More information about the Python-list mailing list