code: def _merge(master, target):
      if type(master) != type(target):
          print("yaml format not match:\n")
          yaml.dump(master, sys.stdout)
          print("\n&&\n")
          yaml.dump(target, sys.stdout)
  
          sys.exit(1)
  
      ## item is a sequence
      if isinstance(target, CommentedSeq):
          for index in range(len(target)):
              # get target comment
              target_comment = _seq_comment(target, index)
  
              master_index = len(master)
  
              target_item = target[index]
  
              if isinstance(target_item, CommentedMap):
                  merge_flag = False
                  for idx in range(len(master)):
                      if isinstance(master[idx], CommentedMap):
                          if master[idx].keys() == target_item.keys():
                              _merge(master[idx], target_item)
                              # nonlocal merge_flag
                              master_index = idx
                              merge_flag = True
                              break
  
                  if merge_flag is False:
                      master.append(target_item)
              elif target_item not in master:
                  master.append(target[index])
              else:
                  # merge(master[index], target[index])
                  pass
  
              # # remove enter signal in previous item
              previous_comment = _seq_comment(master, master_index - 1)
              _add_eol_comment(
                  master,
                  _extract_comment(previous_comment),
                  master_index - 1,
              )
  
              origin_comment = _seq_comment(master, master_index)
              comment = _obtain_comment(origin_comment, target_comment)
              if len(comment) > 0:
                  _add_eol_comment(
                      master,
                      _extract_comment(comment) + "\n\n",
                      len(master) - 1,
                  )
  
      ## item is a map
      elif isinstance(target, CommentedMap):
          for item in target:
              if item == "flag":
                  print("")
              origin_comment = _map_comment(master, item)
              target_comment = _map_comment(target, item)
  
              # get origin start comment
              origin_start_comment = _start_comment(master)
  
              # get target start comment
              target_start_comment = _start_comment(target)
  
              m = master.get(item, default=None)
              if m is None or (
                  not (
                      isinstance(m, CommentedMap)
                      or isinstance(m, CommentedSeq)
                  )
              ):
                  master.update({item: target[item]})
  
              else:
                  _merge(master[item], target[item])
  
              comment = _obtain_comment(origin_comment, target_comment)
              if len(comment) > 0:
                  _add_eol_comment(
                      master, _extract_comment(comment), item
                  )
  
              start_comment = _obtain_comment(
                  origin_start_comment, target_start_comment
              )
              if len(start_comment) > 0:
                  master.yaml_set_start_comment(
                      _extract_comment(start_comment)
                  )
  
imports: import sys
  import argparse
  from argparse import Namespace
  import os, shutil
  import getopt
  from ruamel.yaml import YAML, yaml_object
  from ruamel.yaml.comments import CommentedSeq, CommentedMap
  from ruamel.yaml.tokens import CommentToken
label_desc: Use image node_id 15 for calling a global function with example usage: _merge(master, target) without return types