pythonstringlistspaces

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


How can I convert a list into a space-separated string in Python?

For example, I want to convert this list:

my_list = ["how", "are", "you"]

into the string "how are you".

The spaces are important. I don't want to get "howareyou".


Solution

  • " ".join(my_list)
    

    You need to join with a space, not an empty string.