How to input a Huffman code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Avatar19
    New Member
    • Apr 2010
    • 43

    How to input a Huffman code

    My question is this.
    If i need to be able to input an unspecified amount of Huffman code as raw input
    e.g. A 00
    E 01
    L 100
    encode "Word"
    decode "0100101010 "
    etc etc
    would i use tuples and dictionaries to assign the different input values, because after the unspecified amount of Huffman code has been inputed the final line will contain either "encode" "A word" or "decode" "01010110" finally terminated by a blank line.
    I am very new to python and don;t have much experience as I am pretty much teaching myself.
    Any help in this would be greatly appreciated
    Thank you
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    I would store the text in a list. Example:
    Code:
    >>> textlist = []
    >>> while True:
    ... 	s = raw_input("Enter text or return")
    ... 	if s:
    ... 		textlist.append(s)
    ... 	else:
    ... 		break
    ... 	
    >>> textlist
    ['text1', 'text2', 'text3']
    >>>

    Comment

    • Avatar19
      New Member
      • Apr 2010
      • 43

      #3
      Hmmm yes i definitely see why that would be handy to do.. thank you for your reply!! I had the idea of the taking each list element individually e.g.
      Tlen = len(Textlist)
      then splitting each list element so I can get e.g
      A = 00
      E =01
      C = 101
      but I am unsure of how to code this so i can get a loop to run through each element and equate each letter to its binary counter part?
      Once thank you for your help!!!

      Comment

      Working...