code: def _build_dict_validator(dictionary):
      
      mandatory, optional, types, defaults = _determine_keys(dictionary)
  
      def dict_validator(data):
          """Validate dictionaries."""
          missing = list(defaults.keys())
          if not isinstance(data, dict):
              raise NotValid('%r is not of type dict' % (data,))
  
          validated = {}
          to_validate = list(data.keys())
          errors = _validate_mandatory_keys(
              mandatory, validated, data, to_validate)
          errors.extend(
              _validate_other_keys(
                  optional, types, missing, validated, data, to_validate))
          if errors:
              raise NotValid(*errors)
          for key in missing:
              validated[key] = defaults[key][0]
  
          return validated
  
      return dict_validator
docs: Build a validator from a dictionary.