def _dusort (seq, decorator, reverse = False) :
    """Returns a sorted copy of `seq`. The sorting is done over a
       decoration of the form `decorator (p), i, p for (i, p) in
       enumerate (seq)`.

       >>> _dusort ([1, 3, 5, 2, 4], lambda e : -e)
       [5, 4, 3, 2, 1]
    """
    temp = [(decorator (p), i, p) for (i, p) in enumerate (seq)]
    temp.sort ()
    result = [p [-1] for p in temp]
    if reverse :
        result.reverse ()
    return result