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

2013-12-04 Thread Cameron Simpson
On 04Dec2013 09:44, Helmut Jarausch wrote: > On Wed, 04 Dec 2013 08:13:03 +1100, Cameron Simpson wrote: > > I iterate over Queues so often that I have a personal class called > > a QueueIterator which is a wrapper for a Queue or PriorityQueue > > which is iterable, and an IterablePriorityQueue fac

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

2013-12-04 Thread Peter Otten
Helmut Jarausch wrote: > On Tue, 03 Dec 2013 13:38:58 +0100, Peter Otten wrote: > >> Helmut Jarausch wrote: >> >>> Hi, >>> >>> 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 know I could use

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

2013-12-04 Thread Helmut Jarausch
On Wed, 04 Dec 2013 08:13:03 +1100, Cameron Simpson wrote: > On 03Dec2013 12:18, Helmut Jarausch 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 Pri

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

2013-12-04 Thread Helmut Jarausch
On Tue, 03 Dec 2013 15:56:11 +0200, Jussi Piitulainen wrote: > Helmut Jarausch writes: > ... >> I know I could use a while loop but I don't like it. > ... >> from heapq import heappush, heappop >> # heappop raises IndexError if heap is empty > ... >> # how to avoid / simplify the following functio

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

2013-12-04 Thread Helmut Jarausch
On Tue, 03 Dec 2013 13:06:05 +, Duncan Booth wrote: > Helmut Jarausch wrote: > >> Hi, >> >> 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 know I could use a while loop but I don't like it

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

2013-12-04 Thread Helmut Jarausch
On Tue, 03 Dec 2013 04:40:26 -0800, rusi wrote: > On Tuesday, December 3, 2013 5:48:59 PM UTC+5:30, Helmut Jarausch wrote: >> Hi, >> >> 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 know I could

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

2013-12-04 Thread Helmut Jarausch
On Tue, 03 Dec 2013 13:38:58 +0100, Peter Otten wrote: > Helmut Jarausch wrote: > >> Hi, >> >> 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 know I could use a while loop but I don't like it. >

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

2013-12-03 Thread Cameron Simpson
On 03Dec2013 14:43, Ian Kelly wrote: > On Tue, Dec 3, 2013 at 2:13 PM, Cameron Simpson wrote: > > On 03Dec2013 12:18, Helmut Jarausch 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? >

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

2013-12-03 Thread Ned Batchelder
On 12/3/13 4:43 PM, Ian Kelly wrote: On Tue, Dec 3, 2013 at 2:13 PM, Cameron Simpson wrote: On 03Dec2013 12:18, Helmut Jarausch 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 no

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

2013-12-03 Thread Ian Kelly
On Tue, Dec 3, 2013 at 2:13 PM, Cameron Simpson wrote: > On 03Dec2013 12:18, Helmut Jarausch 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 PriorityQ

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

2013-12-03 Thread Cameron Simpson
On 03Dec2013 12:18, Helmut Jarausch 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. A PriorityQueue (from the queue module in python 3 and t

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

2013-12-03 Thread Jussi Piitulainen
Helmut Jarausch writes: ... > I know I could use a while loop but I don't like it. ... > from heapq import heappush, heappop > # heappop raises IndexError if heap is empty ... > # how to avoid / simplify the following function > > def in_sequence(H) : > try : > while True : > N= heappo

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

2013-12-03 Thread Duncan Booth
Helmut Jarausch wrote: > Hi, > > 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 know I could use a while loop but I don't like it. > > Many thanks for some lessons in Python. > > Here is my clum

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

2013-12-03 Thread rusi
On Tuesday, December 3, 2013 5:48:59 PM UTC+5:30, Helmut Jarausch wrote: > Hi, > > 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 know I could use a while loop but I don't like it. How about def in

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

2013-12-03 Thread Peter Otten
Helmut Jarausch wrote: > Hi, > > 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 know I could use a while loop but I don't like it. > > Many thanks for some lessons in Python. > > Here is my clumsy