How do I convert a list into a string with spaces in Python? How do I convert a list into a string with spaces in Python? python python

How do I convert a list into a string with spaces in Python?


" ".join(my_list)

you need to join with a space not an empty string ...


I'll throw this in as an alternative just for the heck of it, even though it's pretty much useless when compared to " ".join(my_list) for strings. For non-strings (such as an array of ints) this may be better:

" ".join(str(item) for item in my_list)


For Non String list we can do like this as well

" ".join(map(str, my_list))