Steve, imo strangely enough but your suggestion to replace "if...: else:..." with x_y = x + y h[x_y] = h.get(x_y, 1) s=l=o=w=e=d the thing by ~1 sec.