Home > Enterprise >  How to strip multiple lines in a list
How to strip multiple lines in a list

Time:12-04

list_ex=['accidentally,cancel,order,please,thank',
 'add,address',
 'add,address,aged,date,order,put,thank,update,way,would',
 'add,address,appreciate,change,help1,like,much,please,would',
 'add,address,appreciate,order,receive,refund,thank,would']

and I want to output it like

['accidentally','cancel','order','please','thank','add','address','add','address','aged','date','order','put','thank','update','way','would','add','address','appreciate','change','help1','like','much','please','would','add','address','appreciate','order','receive','refund','thank','would']

I tried like this

converted_list=[]
for element in list(list_ex):
    converted_list.append(element.strip('\n'))
set(converted_list)

not getting desired output

CodePudding user response:

You can iterate over list_ex and split each string on comma:

out = []
for string in list_ex:
    out.extend(string.split(','))
  • Related