2010
Join a list of integers in Python

Today, I had to pretty print a list of integers for debugging. This does not work:
>>> t = [1, 2, 3, 4] >>> ' '.join(t) Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: sequence item 0: expected string, int found
So I came up with this:
>>> def concat(x, y): return str(x) + ' ' + str(y) >>> reduce(concat, t) '1 2 3 4'
I am sure there is a better way of doing this!



Alexa.3emyh
without def any function:
>>> t=[1,2,3,4]
>>> ‘ ‘.join([str(y) for y in t])