code: def prioSort(elements):
      
      # Randomize the services before sorting so that equal priority
      # elements are load-balanced.
      random.shuffle(elements)
  
      prio_elems = [(getPriority(e), e) for e in elements]
      prio_elems.sort()
      sorted_elems = [s for (_, s) in prio_elems]
      return sorted_elems
docs: Sort a list of elements that have priority attributes