在python中加入字符串列表,并将每个字符串都用引号引起来
问题描述:
我有:
words = ['hello', 'world', 'you', 'look', 'nice']
我想要拥有:
'"hello", "world", "you", "look", "nice"'
使用Python做到这一点最简单的方法是什么?
What's the easiest way to do this with Python?
答
>>> words = ['hello', 'world', 'you', 'look', 'nice']
>>> ', '.join('"{0}"'.format(w) for w in words)
'"hello", "world", "you", "look", "nice"'