Add quotes to every list element

后端 未结 4 1998
自闭症患者
自闭症患者 2020-12-13 09:10

I\'m very new to python. I need a simple and clear script to add quotes to every list elements. Let me explain more. Here is the my code.

parameters = [\'a\'         


        
4条回答
  •  眼角桃花
    2020-12-13 09:21

    As you asked it, use this:

    parameters = ['a', 'b', 'c']
    ', '.join(map(lambda x: "'" + x + "'", parameters))
    

    Since you're creating an SQL query, please use your database library's features regarding input sanitation (example for mysqldb). You don't want to end up with an issue like Bobby Tables.

提交回复
热议问题