Refactor for-in statement in dict_reduce