Python list of strings to 1 string separated by comma & quotes (, & ")

I have a list of strings: list_of_strings = ["A", "List", "Of", "Strings"]

I want to convert it to one new string looking like:

new_string=""" "A", "List", "Of", "Strings" """

( I tried to use the join function, but i didn't manage to do it properly: ','.join(list_of_strings) )

1 answer

  • answered 2018-11-21 14:16 Pablo Santa Cruz

    You need the double quotes on your string.

    new_string = "  " + ", ".join(['"{}"'.format(x) for x in list_of_strings]) + "  "