def _longest(d):
 return collections.OrderedDict(((k, d[k]) for k in sorted(d, key=len, reverse=True)))

def _longest ( d ) : return collections . OrderedDict ( ( ( k , d [ k ] ) for k in sorted ( d , key = len , reverse = True ) ) )
returns an ordereddict with the contents of the input dictionary d sorted by the length of the keys .