code: def validate_key(key):
      
      if len(key.split()) != 2:
          raise ValueError("'{}' is not in the form '(key) (mode)'".format(key))
      key, mode = key.split()
      if key.lower() not in KEY_TO_SEMITONE:
          raise ValueError(
              "Key {} is invalid; should be e.g. D or C# or Eb".format(key))
      if mode not in ['major', 'minor']:
          raise ValueError(
              "Mode '{}' is invalid; must be 'major' or 'minor'".format(mode))
docs: Checks that a key is well-formatted, e.g. in the form ``'C# major'``.
  
      Parameters
      ----------
      key : str
          Key to verify