def sort_ids(ids, mapping):
 def _lookup(id):
  try:
   return len(mapping[id])
  except KeyError:
   return 0
 deco = [(_lookup(id), id) for id in ids]
 deco.sort(reverse=True)
 return [id for (_, id) in deco]

def sort_ids ( ids , mapping ) : def _lookup ( id ) : try : return len ( mapping [ id ] ) except KeyError : return 0 deco = [ ( _lookup ( id ) , id ) for id in ids ] deco . sort ( reverse = True ) return [ id for ( _ , id ) in deco ]
sorts ids based on their cluster_size .