Convert a list of integers to string
There's definitely a slicker way to do this, but here's a very straight forward way:
mystring = ""
for digit in new:
mystring += str(digit)
Coming a bit late and somehow extending the question, but you could leverage the array
module and use:
from array import array
array('B', new).tobytes()
b'\n\t\x05\x00\x06\x05'
In practice, it creates an array of 1-byte wide integers (argument 'B'
) from your list of integers. The array is then converted to a string as a binary data structure, so the output won't look as you expect (you can fix this point with decode()
). Yet, it should be one of the fastest integer-to-string conversion methods and it should save some memory. See also documentation and related questions:
https://www.python.org/doc/essays/list2str/
https://docs.python.org/3/library/array.html#module-array
Converting integer to string in Python?
With Convert a list of characters into a string you can just do
''.join(map(str,new))
two simple ways of doing this
"".join(map(str, A))
"".join([str(a) for a in A])