Incorporating striplist() into python3 code?
Question: I have a csv reader that pulls data values into a list, once this data has
been put into a list I would like to strip the whitespace in the list. I have
looked online and seen people using `striplist()`

e.g

    
    
    def striplist(l):
        return([x.strip() for x in l])
    

However, being a novice and attempting to incorporate the code, I'm not having
much luck, guidance on the issue or some understanding about what I'm doing
wrong would be greatly appreciated. My code is below:

    
    
    import csv
    
    import time
    
    csvfile = open("example.csv")
    
    filetype = csv.Sniffer().has_header(csvfile.read(1024))
    
    csvfile.seek(0)
    
    reader = csv.reader(csvfile,filetype)
    
    csvreaderlist = []
    
    csvfilecounter = 0
    
    
    if filetype:
        next(reader)
        print("CSV file located, headers present, importing data")
        time.sleep(3)
        for data in reader:
                csvreaderlist.append(data)
                print(data)
                csvfilecounter = csvfilecounter +1
                summarycounter = summarycounter +1
    
    else:
        print("CSV file located, no headers found, importing data")
        time.sleep(3)
        for data in reader:
                csvreaderlist.append(data)
                csvfilecounter = csvfilecounter +1
                summarycounter = summarycounter +1
                print(data)
    
    if csvfilecounter == csvfilecounter:
        print(len(csvreaderlist),'Lines were successfully imported from the CSV file')
        time.sleep(3)
    def striplist(csvreaderlist):
        return([data.strip() for data in csvreaderlist])
    


Answer: an example of your function:

    
    
    def strip_list(the_list):
        return [line.strip() for line in the_list]
    
    lines = ['foo\n', 'bar\r\n', 'baz']
    stripped_list = strip_list(lines)
    print(stripped_list)
    

would output:

    
    
    ['foo', 'bar', 'baz']
    

* * *

and here as an ugly memory inefficient one-liner, just to show using
`splitlines()` :)

    
    
    return ''.join(csvreaderlist).splitlines()
    

