sorting with priority queue in defining the priority queue adtwe noted that any type of object can be used as keybut that any pair of keys must be comparable to each otherand that the set of keys be naturally ordered in pythonit is common to rely on the operator to define such an orderin which case the following properties must be satisfiedirreflexive propertyk  transitive propertyif and then formallysuch relationship defines what is known as strict weak orderas it allows for keys to be considered equal to each otherbut the broader equivalence classes are totally orderedas they can be uniquely arranged from smallest to largest due to the transitive property as our first application of priority queueswe demonstrate how they can be used to sort collection of comparable elements that iswe can produce sequence of elements of in increasing order (or at least in nondecreasing order if there are duplicatesthe algorithm is quite simple--we insert all elements into an initially empty priority queueand then we repeatedly call remove min to retrieve the elements in nondecreasing order an implementation of this algorithm is given in code fragment assuming that is positional list (see we use an original element of the collection as both key and value when calling add(elementelement def pq sort( ) """sort collection of elements stored in positional list "" len( priorityqueue for in range( ) element delete( first) add(elementelementuse element as key and value for in range( ) ( ,vp remove minstore smallest remaining element in add last(vcode fragment an implementation of the pq sort functionassuming an appropriate implementation of priorityqueue class note that each element of the input list serves as its own key in the priority queue with minor modification to this codewe can provide more general supportsorting elements according to an ordering other than the default for examplewhen working with stringsthe operator defines lexicographic orderingwhich is an extension of the alphabetic ordering to unicode for examplewe have that because of the order of the first character of each stringjust as