I just got got by a gotcha. This code acts as you would expect:
keys = range(8)
DICT={}
for k in keys:
DICT[k] = []
print DICT
#returns
#{0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: []}
DICT[1].append('mkay')
print DICT
#returns
#{0: [], 1: ['mkay'], 2: [], 3: [], 4: [], 5: [], 6: [], 7: []}
But if I initialize the dictionary differently, the appending behavior is totally different:
DICT = dict(zip(keys,[[]]*len(keys)))
print DICT
#returns
#{0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: []}
So it looks the same. But it's not:
DICT[1].append('mkay')
print DICT
#returns
#{0: ['mkay'], 1: ['mkay'], 2: ['mkay'], 3: ['mkay'], 4: ['mkay'], 5: ['mkay'], 6: ['mkay'], 7: ['mkay']}
Does anyone know what's going on here? Thought I'd post this as well for anyone else who might get got by it.