I am slightly confused when I use the getsizeof method in the sys module for dictionaries. Below I have created a simple dictionary of two strings.
getsizeof
sys
Well, dictionaries don't store the actual string inside them, it works a bit like C/C++ pointers, so you only get a constant overhead in the dictionary for every element.
The total size is
size = getsizeof(d) size += sum(map(getsizeof, d.itervalues())) + sum(map(getsizeof, d.iterkeys()))