i am trying to write the huffman coding in Python 3 with the code from http://en.literateprograms.org/Huffman_coding_%28Python%29 but it doesn't work. If i run the code in Python 2.7, it works well.
The following lines are the problem:
heapq.heapify(trees)
while len(trees) > 1:
childR, childL = heapq.heappop(trees), heapq.heappop(trees)
parent = (childL[0] + childR[0], childL, childR)
heapq.heappush(trees, parent)
I get a TypeError in heapq.heappush(u,parent): "unorderable types: tuple() < str()"
So i've searched for a solution, and i think, i have to implement a _lt _ function. Its possible that two or more nodes have the same frequency, then heapq tries to compare the tuples and i think, he can't compare a tuple of a tuple. But i dont know where and how i have to create a compare-method to solve this problem? Can anybody help? ;-)