collections.defaultdict Aug 13th, 2011 I learned about this gem today. No more if k not in d: d[k] = []. Examples.