code: def munchify(x, factory=Munch):
      """Recursively transforms a dictionary into a Munch via copy.
  
      >>> b = munchify({'urmom': {'sez': {'what': 'what'}}})
      >>> b.urmom.sez.what
      'what'
  
      munchify can handle intermediary dicts, lists and tuples (as well as
      their subclasses), but ymmv on custom datatypes.
  
      >>> b = munchify({ 'lol': ('cats', {'hah':'i win again'}),
      ...         'hello': [{'french':'salut', 'german':'hallo'}] })
      >>> b.hello[0].french
      'salut'
      >>> b.lol[1].hah
      'i win again'
  
      nb. As dicts are not hashable, they cannot be nested in sets/frozensets.
      """
      # Munchify x, using `seen` to track object cycles
      seen = dict()
  
      def munchify_cycles(obj):
          # If we've already begun munchifying obj, just return the already-created munchified obj
          try:
              return seen[id(obj)]
          except KeyError:
              pass
  
          # Otherwise, first partly munchify obj (but without descending into any lists or dicts) and save that
          seen[id(obj)] = partial = pre_munchify(obj)
          # Then finish munchifying lists and dicts inside obj (reusing munchified obj if cycles are encountered)
          return post_munchify(partial, obj)
  
      def pre_munchify(obj):
          # Here we return a skeleton of munchified obj, which is enough to save for later (in case
          # we need to break cycles) but it needs to filled out in post_munchify
          if isinstance(obj, Mapping):
              return factory({})
          elif isinstance(obj, list):
              return type(obj)()
          elif isinstance(obj, tuple):
              type_factory = getattr(obj, "_make", type(obj))
              return type_factory(munchify_cycles(item) for item in obj)
          else:
              return obj
  
      def post_munchify(partial, obj):
          # Here we finish munchifying the parts of obj that were deferred by pre_munchify because they
          # might be involved in a cycle
          if isinstance(obj, Mapping):
              partial.update(
                  (k, munchify_cycles(obj[k])) for k in obj.keys()
              )
          elif isinstance(obj, list):
              partial.extend(munchify_cycles(item) for item in obj)
          elif isinstance(obj, tuple):
              for item_partial, item in zip(partial, obj):
                  post_munchify(item_partial, item)
  
          return partial
  
      return munchify_cycles(x)
  
imports: from collections.abc import Mapping
label_desc: Use image node_id 1 for calling a global function with example usage: munchify(x, factory) and returns: munchify_cycles, post_munchify, partial, seen, factory, type, type_factory, obj