I am getting a list of lists from this code, and I just want a list. What am I missing? gene list.csv is a simple csv file with one element per line. This code produces a list of each gene in a separate list like: [['IFNAR2'], ['AKT1'], ['AKT2'], ['IFNAR1']]
gene_list = list(csv.reader(open("genelist.csv")))
If all your file contains are one element per line, don’t use the
csvmodule. Just read the file directly:The
csvmodule is used to parse multiple comma, space or tab-separated values per line, and thus each line is returned as a list of columns.If you must use
csvfor the file, ‘unwrapping’ the resulting nested lists is easy enough:That is a list comprehension, that takes the first column of each row produced by the
csv.reader()call.