How do I convert a list of ascii values to a string in python? How do I convert a list of ascii values to a string in python? python python

How do I convert a list of ascii values to a string in python?


You are probably looking for 'chr()':

>>> L = [104, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100]>>> ''.join(chr(i) for i in L)'hello, world'


Same basic solution as others, but I personally prefer to use map instead of the list comprehension:

>>> L = [104, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100]>>> ''.join(map(chr,L))'hello, world'


import arraydef f7(list):    return array.array('B', list).tostring()

from Python Patterns - An Optimization Anecdote