Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #60971

Re: extracting a heapq in a for loop - there must be more elegant solution

Date 2013-12-04 10:27 +1100
From Cameron Simpson <cs@zip.com.au>
Subject Re: extracting a heapq in a for loop - there must be more elegant solution
References <CALwzidmmqLzFtNyRVmcY6j7gvRxPQh-vNune4XXXzrqMjChapA@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.3538.1386113252.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 03Dec2013 14:43, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> On Tue, Dec 3, 2013 at 2:13 PM, Cameron Simpson <cs@zip.com.au> wrote:
> > On 03Dec2013 12:18, Helmut Jarausch <jarausch@igpm.rwth-aachen.de> wrote:
> >> I'd like to extracted elements from a heapq in a for loop.
> >> I feel my solution below is much too complicated.
> >> How to do it more elegantly?
> >
> > I can't believe nobody has mentioned PriorityQueue.
> 
> As far as I'm aware, the only advantage of PriorityQueue over heapq is
> that the former is thread-safe, which does not appear to be relevant
> here.  I haven't tested it for speed, but I imagine it would be a fair
> bit slower, mostly thanks to the locking it needs to do.

I could claim I do a lot of multithreaded stuff, which is true.

But really I just prefer the put/get abstraction. A heapq is very
overtly a heap manipulator applied to an arbitrary list. A Queue
is more self contained, for all that it is the same thing happening
inside.

Cheers,
-- 
Cameron Simpson <cs@zip.com.au>

"Are we alpinists, or are we tourists" followed by "tourists! tourists!"
        - Kobus Barnard <kobus@cs.sfu.ca> in rec.climbing,
          on things he's heard firsthand

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: extracting a heapq in a for loop - there must be more elegant solution Cameron Simpson <cs@zip.com.au> - 2013-12-04 10:27 +1100

csiph-web