Week 2 – Cleaning data with list comprehension

by Security Dude

data = ['vincent\n','was\n','here\n','but\n','he\n','wasnt\n','there\n']
cleaned_data=[]
for line in data:
    cleaned_data.append(line.strip('\n')

<<<<<<<<<<<<<<<<<<<< or >>>>>>>>>>>>>>>>>>>>>
data = ['vincent\n','was\n','here\n','but\n','he\n','wasnt\n','there\n']
data = [ line.strip('\n') for line in data ]
Advertisements