I've made this formula which turns a CSV into a dictionary:
def CSVtoDict(BDF, mode):
saved={}
with open('%s%s.csv' % (dataDir,BDF), mode='r') as infile:
reader = csv.reader(infile)
for row in reader:
if mode is 'prune' and row == '':
break
else:
pass
key = row[0]
saved[key]=row[1:]
return saved
I'm trying to make it so that when the mode is 'prune', any string from the CSV such as ['data1', 'data2', '', '', ''] is returned without any ''. But the break statement doesn't seem to work for some reason and things are returned as if there was no if else.
Also do you know what would be the pythonic way of doing this? I feel like this could be more efficient somehow...
Example line from the CSV:
Awareness,ASD,ASD2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,