def CollectObjectIDs(ids, obj):
 if (id(obj) in ids):
  return
 ids.add(id(obj))
 if isinstance(obj, (list, tuple, set, frozenset)):
  for e in obj:
   CollectObjectIDs(ids, e)
 elif isinstance(obj, dict):
  for (k, v) in obj.items():
   CollectObjectIDs(ids, k)
   CollectObjectIDs(ids, v)
 return len(ids)

def CollectObjectIDs ( ids , obj ) : if ( id ( obj ) in ids ) : return ids . add ( id ( obj ) ) if isinstance ( obj , ( list , tuple , set , frozenset ) ) : for e in obj : CollectObjectIDs ( ids , e ) elif isinstance ( obj , dict ) : for ( k , v ) in obj . items ( ) : CollectObjectIDs ( ids , k ) CollectObjectIDs ( ids , v ) return len ( ids )
collect object ids seen in a structure .