I have a
defaultdict being written to file like this:
writer = csv.writer(open(locationToSaveFile, 'wb+')) for k,v in dict.iteritems(): writer.writerow([k ,v])
I then have this horribly convoluted text to read it back in:
myDict = defaultdict(list) with open(fileLocation, 'rb') as test: reader = csv.DictReader(test, ['processedText', 'date']) for line in reader: myDict[line['processedText']].append(line['date']) textDict = defaultdict(list) for processedText, date in myDict.items(): actual_list = ast.literal_eval(date) for a in actual_list: textDict[processedText].append(a) for processedText, date in textDict.items():
Obviously this looks very wasteful (and looks horrible!) but I don't know how else to import the
When opening it with the
reader = and
for line in reader lines it creates a list within a list. The only way out of this is to use
ast to convert it.
Could somebody advise me how to tidy this up?
Note: I'm very unfamiliar with Python