I've got a dictionary of dictionaries but each key has a differing number of dictionaries as value. Also, the keys for the nested dictionary can take three different forms.
myDict = {
    u'A': {'1998': u'ATLANTA'},
    u'B': {'1999': u'MANNHEIM'},
    u'C': {'2000': u'BERLIN'},
    u'D': {'1998': u'CHICAGO', '1999': u'PRINCETON'},
    u'E': {'2000': u'LOUISIANA'},
    u'F': {'1998': u'NEW YORK', '1999': u'NEW YORK'}
}
I want to write myDict as a table looking like
  | 1998     | 1999     | 2000
A | ATLANTA  |          |
B |          | MANNHEIM |
C |          |          | BERLIN
D |          | CHICAGO  | PRINCETON
E |          |          | LOUISANA
F | NEW YORK | NEW YORK |
How would I do this? I tried using a DictWriter and a Writer from csv, but both don't work:
DictWriter:
import csv
with open("outfilename.csv", 'w') as f:
    fieldnames = ['author', '1998', '1999', '2000']
    csvWriter = csv.DictWriter(f, fieldnames)
    csvWriter.writerows(myDict)
results in:
  File "./011_create_node_lists.py", line 122, in <module>
    csvWriter.writerows(myDict)
  File "/usr/lib/python2.7/csv.py", line 157, in writerows
    rows.append(self._dict_to_list(rowdict))
  File "/usr/lib/python2.7/csv.py", line 149, in _dict_to_list
    return [rowdict.get(key, self.restval) for key in self.fieldnames]
AttributeError: 'unicode' object has no attribute 'get'
writer:
import csv
with open("outfilename.csv", 'w') as f:
    csvWriter = csv.writer(f)
    for key, value in myDict.items():
       csvWriter.writerow([key, value])
results in:
A | {'1998': u'ATLANTA'}
B | {'1999': u'MANNHEIM'}
C | {'2000': u'BERLIN'}
D | {'1998': u'CHICAGO'    | '1999': u'PRINCETON'}
E | {'2000': u'LOUISIANA'}
F | {'1998': u'NEW YORK'   | '1999': u'NEW YORK'}
Additionally, I am not even sure whether it's the best way to print a structured table.
 
     
     
    