Ah, the solution is simple. Check for identical keys only when about to resize: /* if fill >= 2/3 size, double in size */ if (mp->ma_fill*3 >= mp->ma_size*2) { ***** test here ***** if (dictresize(mp, mp->ma_used*2) != 0) { if (mp->ma_fill+1 > mp->ma_size) return -1; } } --Guido van Rossum (home page: http://www.python.org/~guido/)