The collections.Count.most_common function in Python uses the heapq module to return the count of the most common word in a file, for instance.
I have traced through the heapq.py file, but I’m having a bit of trouble understanding how a heap is created/updated with respect to words let’s say.
So, I think the best way for me to understand it, is to figure out how to create a heap from scratch.
Can someone provide a pseudocode for creating a heap that would represent word count?
this is a slightly modified version of the code found here : http://code.activestate.com/recipes/577086-heap-sort/
Output
you can visualize the program here
http://goo.gl/2a9Bh