[Python-ideas] priorityqueue, sortedlist in collections?

Jim Jewett jimjjewett at gmail.com
Fri Mar 2 19:37:35 CET 2007


On 3/1/07, Adam Olsen <rhamph at gmail.com> wrote:
> On 3/1/07, Jason Orendorff <jason.orendorff at gmail.com> wrote:

> >   class priorityqueue:
> Should inherit from object if this is going into 2.x.

> >       def __init__(self, elements=(), *,
> >           cmp=None, key=None, reversed=False)
> >       def add(self, element)
> >       def pop(self)  --> remove and return the min element
> >       def __iter__(self) --> (while self: yield self.pop())
> __iter__ shouldn't modify the container.

generators do not need to be reiterable.

lists are reiterable, but I wouldn't expect a socket (treated as a file) to be.

For a queue that is already sorted, the natural use case is to take
the task and do it, explicitly adding it back to the end if need be.
I would expect an operation that *didn't* remove things from the queue
to have view in the name somewhere.

-jJ



More information about the Python-ideas mailing list