Removing Square Brackets and Double quotes from list

前端 未结 3 1019
情深已故
情深已故 2021-01-20 09:14

I need to remove Square brackets and Double quotes from python list for further processing of data.

My code for the same is as follows:

ips = [\'1.2.         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-20 09:45

    So, you do want to make a string from list? That's simple, you can use str.join to do this:

    ips = ['1.2.3.5','1.2.3.4']
    
    # this is list comprehension, it does the same thing as your loop
    y = ["model.data.like('%"+ip+"%')" for ip in ips]
    
    print  ','.join(y)
    

提交回复
热议问题