def dictlike_iteritems(dictlike):
 if compat.py3k:
  if hasattr(dictlike, 'items'):
   return list(dictlike.items())
 elif hasattr(dictlike, 'iteritems'):
  return dictlike.iteritems()
 elif hasattr(dictlike, 'items'):
  return iter(dictlike.items())
 getter = getattr(dictlike, '__getitem__', getattr(dictlike, 'get', None))
 if (getter is None):
  raise TypeError(("Object '%r' is not dict-like" % dictlike))
 if hasattr(dictlike, 'iterkeys'):
  def iterator():
   for key in dictlike.iterkeys():
    (yield (key, getter(key)))
  return iterator()
 elif hasattr(dictlike, 'keys'):
  return iter(((key, getter(key)) for key in dictlike.keys()))
 else:
  raise TypeError(("Object '%r' is not dict-like" % dictlike))

def dictlike_iteritems ( dictlike ) : if compat . py3k : if hasattr ( dictlike , 'items' ) : return list ( dictlike . items ( ) ) elif hasattr ( dictlike , 'iteritems' ) : return dictlike . iteritems ( ) elif hasattr ( dictlike , 'items' ) : return iter ( dictlike . items ( ) ) getter = getattr ( dictlike , '__getitem__' , getattr ( dictlike , 'get' , None ) ) if ( getter is None ) : raise TypeError ( ( "Object '%r' is not dict-like" % dictlike ) ) if hasattr ( dictlike , 'iterkeys' ) : def iterator ( ) : for key in dictlike . iterkeys ( ) : ( yield ( key , getter ( key ) ) ) return iterator ( ) elif hasattr ( dictlike , 'keys' ) : return iter ( ( ( key , getter ( key ) ) for key in dictlike . keys ( ) ) ) else : raise TypeError ( ( "Object '%r' is not dict-like" % dictlike ) )
return a iterator for almost any dict-like object .