title: How can I create a tree for Huffman encoding and decoding?
body: <p>For my assignment, I am to do a encode and decode for huffman trees. I have a problem creating my tree, and I am stuck.</p>
  
  <p>Don't mind the print statements - they are just for me to test and see what the output is when my function runs.</p>
  
  <p>For the first for loop, I got all the values and index from the text file I used in my main block for testing.</p>
  
  <p>In the second for loop I inserted all the stuff into the priority queue.</p>
  
  <p>I am so stuck about where to go next - I'm trying to make nodes, but I am confused about how to progress. Can someone tell me if I'm doing this right?</p>
  
  <pre><code>def _create_code(self, frequencies):
      '''(HuffmanCoder, sequence(int)) -&gt; NoneType
      iterate over index into the sequence keeping it 256 elements long, '''
      #fix docstring
      p = PriorityQueue()
      print frequencies
  
      index = 0 
      for value in frequencies:
          if value != 0:
              print value #priority
              print index #elm
              print '-----------'       
          index = index + 1
  
  
      for i in range(len(frequencies)):
          if frequencies[i] != 0:
              p.insert(i, frequencies[i])  
              print i,frequencies[i]
              if p.is_empty():
                  a = p.get_min()
                  b = p.get_min()
                  n1 = self.HuffmanNode(None, None, a)
                  n2 = self.HuffmanNode(None, None, b)
                  print a, b, n1, n2
      while not p.is_empty():
          p.get_min()
  </code></pre>
  
  <p>I manually inserted the first two to start my tree, is that correct?</p>
  
  <p>How do I keep going? I know the idea of it, just code-wise I am very stuck. </p>
  
  <p>This is using python by the way. I tried looking at Wikipedia, I know the steps, I just need help on code and how I should keep going, thanks!</p>
  
  <p>The HuffmanNode comes from this nested class:</p>
  
  <pre><code>class HuffmanNode(object):
  
      def __init__(self, left=None, right=None, root=None):
          self.left = left
          self.right = right
          self.root = root
  </code></pre>