def duck_type_collection(specimen, default=None):
 if hasattr(specimen, '__emulates__'):
  if ((specimen.__emulates__ is not None) and issubclass(specimen.__emulates__, set)):
   return set
  else:
   return specimen.__emulates__
 isa = ((isinstance(specimen, type) and issubclass) or isinstance)
 if isa(specimen, list):
  return list
 elif isa(specimen, set):
  return set
 elif isa(specimen, dict):
  return dict
 if hasattr(specimen, 'append'):
  return list
 elif hasattr(specimen, 'add'):
  return set
 elif hasattr(specimen, 'set'):
  return dict
 else:
  return default

def duck_type_collection ( specimen , default = None ) : if hasattr ( specimen , '__emulates__' ) : if ( ( specimen . __emulates__ is not None ) and issubclass ( specimen . __emulates__ , set ) ) : return set else : return specimen . __emulates__ isa = ( ( isinstance ( specimen , type ) and issubclass ) or isinstance ) if isa ( specimen , list ) : return list elif isa ( specimen , set ) : return set elif isa ( specimen , dict ) : return dict if hasattr ( specimen , 'append' ) : return list elif hasattr ( specimen , 'add' ) : return set elif hasattr ( specimen , 'set' ) : return dict else : return default
given an instance or class .