code: def named_objs(objlist, namesdict=None):
      
      objs = OrderedDict()
  
      if namesdict is not None:
          objtoname = {hashable(v): k for k, v in namesdict.items()}
  
      for obj in objlist:
          if namesdict is not None and hashable(obj) in objtoname:
              k = objtoname[hashable(obj)]
          elif hasattr(obj, "name"):
              k = obj.name
          elif hasattr(obj, '__name__'):
              k = obj.__name__
          else:
              k = as_unicode(obj)
          objs[k] = obj
      return objs
docs: Given a list of objects, returns a dictionary mapping from
      string name for the object to the object itself. Accepts
      an optional name,obj dictionary, which will override any other
      name if that item is present in the dictionary.