So I have a problem to solve for a practice task. The task is to develop a function which reads csv data from a file into memory, but we cannot use any libraries to do so. So i can't use csv reader, Pandas, NumPy etc.
This is what I have come up with, but it does not work as it says 'csv_list is not defined'. I am a bit stuck on where to go from here, and have maninly only coded using libraries, so coding manually and developing functions myself are a struggle! I have looked on here for any solutions but none of them seem to work / they use libraries which I cannot use. If anyone has a way to do this I would be so grateful!
#define read csv
def read_csv (file_name):
with open(file_name) as f:
csv_list = [[val.strip() for val in r.split (",")] for r in f.readlines()]
#convert file to dictionary structure
(_, *header), *data = csv_list
csv_dict = {}
for row in data:
key, *values = row
csv_dict[key] = {key: value for key, value in zip(header, values)}
#insert name of file to be read by user
read_csv (task1.csv)
for r in f.readlines(). Just dofor r in f.fis an iterator that iterates over the file's lines anyway