Importing .csv values as single list in Python

Viewed 14496

I have a csv file that has one column of records that looks like this:

test1
test2
test3
...

I imported them into a Python list using this:

import csv

results = []
with open('test.csv', newline='') as inputfile:
    for row in csv.reader(inputfile):
        results.append(row)

print(results)

That worked fine, however, it prints them out like this:

[['test1'],['test2'],['test3']]

How would I adjust my code to have them print out in a single list instead like this:

['test1','test2','test3']

and, is one output more preferred than the other? I realize it is use-case dependent. I am just curious how others work with imported lists via .csv, and what advantage one would have over the other.

Thanks!

1 Answers
Related