implementing priority queue in this sectionwe show how to implement priority queue by storing its entries in positional list (see section we provide two realizationsdepending on whether or not we keep the entries in sorted by key the composition design pattern one challenge in implementing priority queue is that we must keep track of both an element and its keyeven as items are relocated within our data structure this is reminiscent of case study from section in which we maintain access counts with each element in that settingwe introduced the composition design patterndefining an item class that assured that each element remained paired with its associated count in our primary data structure for priority queueswe will use composition to store items internally as pairs consisting of key and value to implement this concept for all priority queue implementationswe provide priorityqueuebase class (see code fragment that includes definition for nested class named item we define the syntax bfor item instances and bto be based upon the keys class priorityqueuebase """abstract base class for priority queue "" class item """lightweight composite to store priority queue items ""slots _key _value def init (selfkv) self key self value def lt (selfother)compare items based on their keys return self key other key concrete method assuming abstract len def is empty(self) """return true if the priority queue is empty "" return len(self= code fragment priorityqueuebase class with nested item class that composes key and value into single object for conveniencewe provide concrete implementation of is empty that is based on presumed len impelementation