Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:24:06) [MSC v.1600 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> ================================ RESTART ================================ >>> >>> char_count("good morning intro to Python") {'r': 2, 'P': 1, 'o': 6, 't': 3, 'g': 2, ' ': 4, 'h': 1, 'y': 1, 'd': 1, 'm': 1, 'n': 4, 'i': 2} >>> cnt = char_count("a"*8 + "b"*3 + "cdegh") >>> cnt {'h': 1, 'a': 8, 'c': 1, 'g': 1, 'd': 1, 'e': 1, 'b': 3} >>> tree = build_huffman_tree(cnt) >>> tree ['a', [['e', ['h', 'c']], [['g', 'd'], 'b']]] >>> cnt = char_count("a"*8 + "b"*3 + "cdefgh") >>> tree = build_huffman_tree(cnt) >>> tree ['a', [[['h', 'f'], ['c', 'g']], [['d', 'e'], 'b']]] >>> tree[0] 'a' >>> tree[1] [[['h', 'f'], ['c', 'g']], [['d', 'e'], 'b']] >>> code = generate_code(tree) >>> code {'f': '1001', 'a': '0', 'e': '1101', 'h': '1000', 'g': '1011', 'c': '1010', 'd': '1100', 'b': '111'} >>> d = {1:2, 3:4} >>> l = d.items() >>> l dict_items([(1, 2), (3, 4)]) >>> l = list(d.items()) >>> l [(1, 2), (3, 4)] >>> compress("abca", code) '011110100' >>> build_decoding_dict(code) {'1000': 'h', '1010': 'c', '0': 'a', '1011': 'g', '1101': 'e', '111': 'b', '1001': 'f', '1100': 'd'} >>> dec = build_decoding_dict(code) >>> decompress('011110100', dec) 'abca' >>>