code: def ruamel_structure(data, validator=None):
      
      if isinstance(data, dict):
          if len(data) == 0:
              raise exceptions.CannotBuildDocumentsFromEmptyDictOrList(
                  "Document must be built with non-empty dicts and lists"
              )
          return CommentedMap(
              [
                  (ruamel_structure(key), ruamel_structure(value))
                  for key, value in data.items()
              ]
          )
      elif isinstance(data, list):
          if len(data) == 0:
              raise exceptions.CannotBuildDocumentsFromEmptyDictOrList(
                  "Document must be built with non-empty dicts and lists"
              )
          return CommentedSeq([ruamel_structure(item) for item in data])
      elif isinstance(data, bool):
          return u"yes" if data else u"no"
      elif isinstance(data, (int, float)):
          return str(data)
      else:
          if not is_string(data):
              raise exceptions.CannotBuildDocumentFromInvalidData(
                  (
                      "Document must be built from a combination of:\n"
                      "string, int, float, bool or nonempty list/dict\n\n"
                      "Instead, found variable with type '{}': '{}'"
                  ).format(type(data).__name__, data)
              )
          return data
docs: Take dicts and lists and return a ruamel.yaml style
      structure of CommentedMaps, CommentedSeqs and
      data.
  
      If a validator is presented and the type is unknown,
      it is checked against the validator to see if it will
      turn it back in to YAML.