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


Groups > comp.lang.python > #60967

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

From Ned Batchelder <ned@nedbatchelder.com>
Subject Re: extracting a heapq in a for loop - there must be more elegant solution
Date 2013-12-03 17:32 -0500
References <bg60hjF83eoU1@mid.dfncis.de> <20131203211303.GA83257@cskk.homeip.net> <CALwzidmmqLzFtNyRVmcY6j7gvRxPQh-vNune4XXXzrqMjChapA@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.3534.1386109973.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 12/3/13 4:43 PM, Ian Kelly 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.
>

In fact, if you look at the implementation of PriorityQueue, it uses a 
heapq internally, so yes, other than the locking, the speed will be the 
same.

--Ned.

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


Thread

extracting a heapq in a for loop - there must be  more elegant solution Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2013-12-03 12:18 +0000
  Re: extracting a heapq in a for loop - there must be more elegant solution Peter Otten <__peter__@web.de> - 2013-12-03 13:38 +0100
    Re: extracting a heapq in a for loop - there must be more elegant solution Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2013-12-04 09:36 +0000
      Re: extracting a heapq in a for loop - there must be more elegant solution Peter Otten <__peter__@web.de> - 2013-12-04 10:50 +0100
  Re: extracting a heapq in a for loop - there must be  more elegant solution rusi <rustompmody@gmail.com> - 2013-12-03 04:40 -0800
    Re: extracting a heapq in a for loop - there must be  more elegant solution Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2013-12-04 09:37 +0000
  Re: extracting a heapq in a for loop - there must be  more elegant solution Duncan Booth <duncan.booth@invalid.invalid> - 2013-12-03 13:06 +0000
    Re: extracting a heapq in a for loop - there must be  more elegant solution Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2013-12-04 09:39 +0000
  Re: extracting a heapq in a for loop - there must be  more elegant solution Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-12-03 15:56 +0200
    Re: extracting a heapq in a for loop - there must be  more elegant solution Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2013-12-04 09:41 +0000
  Re: extracting a heapq in a for loop - there must be  more elegant solution Cameron Simpson <cs@zip.com.au> - 2013-12-04 08:13 +1100
    Re: extracting a heapq in a for loop - there must be  more elegant solution Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2013-12-04 09:44 +0000
      Re: extracting a heapq in a for loop - there must be  more elegant solution Cameron Simpson <cs@zip.com.au> - 2013-12-05 13:29 +1100
  Re: extracting a heapq in a for loop - there must be more elegant solution Ian Kelly <ian.g.kelly@gmail.com> - 2013-12-03 14:43 -0700
  Re: extracting a heapq in a for loop - there must be more elegant solution Ned Batchelder <ned@nedbatchelder.com> - 2013-12-03 17:32 -0500

csiph-web