create a list of tuples from csv file
csv, list, python, tuples
Solution
`split` returns a list, if you want a tuple, convert it to a tuple:
data_list.append(tuple(line.strip().split(',')))
Please use the `csv` module.
Problem
I am python beginner struggling to create and save a list containing tuples from csv file in python. The code I got for now is: ``` def load_file(filename): fp = open(filename, 'Ur') data_list = [] for line in fp: data_list.append(line.strip().split(',')) fp.close() return data_list ``` and then I would like to save the file ``` def save_file(filename, data_list): fp = open(filename, 'w') for line in data_list: fp.write(','.join(line) + '\n') fp.close() ``` Unfortunately, my code returns a list of lists, not a list of tuples... Is there a way to create one list containing multiple tuples without using csv module?