numbers to string
Robert Kern
robert.kern at gmail.com
Tue Oct 24 22:53:45 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.)
With numpy, something like the following:
>>> from numpy import *
>>> y = [116, 114, 121, 32, 116, 104, 105, 115]
>>> a = array(y, dtype=uint8)
>>> z = a.tostring()
>>> z
'try this'
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list
mailing list