I believe this line has complexity n**2, where n is the number of keys.