It uses recursion too. The unflattening algorithm uses a similar dictionary and a stack. A more efficient version may use binary encodings. When the instruction stream ends, the top of the stack contains the object of interest. The dictionary is used as a way to refer to objects by their 'local name'.
Local names are integers.
They are meaningful only within one flattened data stream. Objects that occur only once in the flattened object also needn't have a local name. It is also up to the flattener to choose a name for an object. We also define a way to refer to objects with global names. These are not defined by the flatten module but by its caller.