heapq iteration?

Eric @ Zomething eric at zomething.com
Wed Mar 17 16:02:12 CET 2004


I'm missing something critical about how heapq works.  I assumed I could iterate through the heap, but I get partial iteration:

>>> listB
[56, 208, 89, 413, 273, 199, 73, 21, 89, 13, 27, 199, 273, 413, 11, 22, 56, 2, 208]
>>> heapify(listB)
>>> for h in listB:
	m=heappop(listB)
	print m, '\t',listB

	
2 	[11, 13, 73, 21, 27, 199, 89, 22, 89, 273, 56, 199, 273, 413, 208, 208, 56, 413]
11 	[13, 21, 73, 22, 27, 199, 89, 56, 89, 273, 56, 199, 273, 413, 208, 208, 413]
13 	[21, 22, 73, 56, 27, 199, 89, 208, 89, 273, 56, 199, 273, 413, 208, 413]
21 	[22, 27, 73, 56, 56, 199, 89, 208, 89, 273, 413, 199, 273, 413, 208]
22 	[27, 56, 73, 56, 208, 199, 89, 208, 89, 273, 413, 199, 273, 413]
27 	[56, 56, 73, 89, 208, 199, 89, 208, 413, 273, 413, 199, 273]
56 	[56, 89, 73, 208, 208, 199, 89, 273, 413, 273, 413, 199]
56 	[73, 89, 89, 208, 208, 199, 199, 273, 413, 273, 413]
73 	[89, 89, 199, 208, 208, 199, 413, 273, 413, 273]
89 	[89, 208, 199, 208, 273, 199, 413, 273, 413]
>>> 


TIA,

Eric




More information about the Python-list mailing list