title: A reviewer of my code said the code working fine except it is failing for one edge case
body: <blockquote>
    <p>Algorithms &amp; Data Structures. This venture covers an assortment of
    subjects identified with the information structures. I have composed a
    perfect and productive answer in Python, just as a content
    clarification of the proficiency of my code and my structure
    decisions.</p>
  </blockquote>
  
  <h2>Explanation</h2>
  
  <p>I have implemented the Huffman encoding technique herewith the following steps: i) Calculate the occurrence of each character in a string. ii) The character with the highest occurrence is encoded with minimum code length ie 1 then next Character as 01 and then 001 and so on.</p>
  
  <p>Time Complexity
  Time complexity: O(n)</p>
  
  <p>Space Complexity
  Space complexity: O(distinct_characters)</p>
  
  <hr>
  
  <p>I am seeking better explanations of this.</p>
  
  <pre><code>import sys
  global huff
  
  def huffman_encoding(data):
      global huff
      huff = {}
      for char in data:
          huff[char] = huff.get(char, 0) + 1
      tree = {}
      temp = '1'
      for num in sorted(huff.items(), key = lambda x: x[1]):
          tree[num[0]] = temp
          temp = '0' + temp
  
      encode = ''
      for d in data:
          encode += tree[d]
      return encode, tree
  
  def huffman_decoding(data,tree):
      huff = {}
      for char in tree:
          huff[tree[char]] = char
      #print(huff)
      temp = ''
      decode = ''
      for d in data:
          if d == '1':
              decode += huff[temp + d]
              temp = ''
          else:
              temp += d
      return decode
  
  if __name__ == "__main__":
      codes = {}
  
      a_great_sentence = "The bird is the word"
  
      print ("The size of the data is: {}\n".format(sys.getsizeof(a_great_sentence)))
      print ("The content of the data is: {}\n".format(a_great_sentence))
  
      encoded_data, tree = huffman_encoding(a_great_sentence)
      # print(tree)
      # print(encoded_data)
      print ("The size of the encoded data is: {}\n".format(sys.getsizeof(int(encoded_data, base=2))))
      print ("The content of the encoded data is: {}\n".format(encoded_data))
  
      decoded_data = huffman_decoding(encoded_data, tree)
  
      print ("The size of the decoded data is: {}\n".format(sys.getsizeof(decoded_data)))
      print ("The content of the decoded data is: {}\n".format(decoded_data))
  </code></pre>