def sdm_sort(f, O):
 return sorted(f, key=(lambda term: O(term[0])), reverse=True)

def sdm_sort ( f , O ) : return sorted ( f , key = ( lambda term : O ( term [ 0 ] ) ) , reverse = True )
sort terms in f using the given monomial order o .