refactoring of dict iterations using six