[Python-ideas] priorityqueue, sortedlist in collections?

Collin Winter collinw at gmail.com
Fri Mar 2 19:45:57 CET 2007


On 3/2/07, Jim Jewett <jimjjewett at gmail.com> wrote:
> 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.

I would be incredibly surprised if

for x in queue:
    ....

destroyed the queue. __iter__ should be implemented non-destructively.

Collin Winter



More information about the Python-ideas mailing list