Join a list of strings in python and wrap each string in quotation marks

kadrian picture kadrian · Aug 17, 2012 · Viewed 73.1k times · Source

I've got:

words = ['hello', 'world', 'you', 'look', 'nice']

I want to have:

'"hello", "world", "you", "look", "nice"'

What's the easiest way to do this with Python?

Answer

jamylak picture jamylak · Aug 17, 2012
>>> words = ['hello', 'world', 'you', 'look', 'nice']
>>> ', '.join('"{0}"'.format(w) for w in words)
'"hello", "world", "you", "look", "nice"'