@@ -0,0 +1,1189 @@
+# coding: utf-8%0Aimport sys%0Afrom queue import PriorityQueue%0A%0A%0Aclass Node:%0A    def __init__(self, value, left=None, right=None):%0A        self.value = value%0A        self.left = left%0A        self.right = right%0A        self.codes = %5B%5D%0A%0A    def __lt__(self, other):%0A        return self.value %3C other.value%0A%0A    def huffman_codes(self, node, code):%0A        if node.left is None:%0A            self.codes.append(code)%0A        else:%0A            self.huffman_codes(node.left, code + '0')%0A            self.huffman_codes(node.right, code + '1')%0A%0A    def __str__(self):%0A        self.codes = %5B%5D%0A        self.huffman_codes(self, '')%0A        return 'value=%7B%7D, codes=%7B%7D'.format(self.value, self.codes)%0A%0A%0Adef huffman_tree(probs):%0A    q = PriorityQueue()%0A    for p in probs:%0A        q.put(Node(p))%0A    while True:%0A        left = q.get()%0A        if q.empty():%0A            return left%0A        right = q.get()%0A        q.put(Node(%0A            left.value + right.value,%0A            left=left, right=right,%0A        ))%0A%0A%0Afor line in sys.stdin:%0A    line = line.rstrip()%0A# line is comma separated probs or freqs (e.g. 5,2,2,1,1)%0A    probs = list(map(lambda x: float(x), line.split(',')))%0A    print(huffman_tree(probs))%0A

add script to get huffman codes.