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

前端 未结 5 973
时光说笑
时光说笑 2020-12-04 11:54

I\'ve got:

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

I want to have:

\'\"hello\", \"world\", \"you\", \"l         


        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 12:25

    An updated version of @jamylak answer with F Strings (for python 3.6+), I've used backticks for a string used for a SQL script.

    keys = ['foo', 'bar' , 'omg']
    ', '.join(f'`{k}`' for k in keys)
    # result: '`foo`, `bar`, `omg`'
    

提交回复
热议问题