We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

temp here is obviously a poor variable name choice. The variable head should be left untouched and a new variable, forexample current_node or just node should be used to traverse the tree down.

defis_last(node):returnnotnode.leftandnotnode.rightdefgo_right(node):returnnode.rightdefgo_left(node):returnnode.left# Enter your code here. Read input from STDIN. Print output to STDOUTdefdecodeHuff(root,s):result=[]node=rootforcharins:ifchar=='1':node=go_right(node)elifchar=='0':node=go_left(node)ifis_last(node):result.append(node.data)node=rootprint''.join(result)

I don't see how exactly your solution is different. Additionaly, temp has a local scope and leaves the root un bothered in the original solution. I can't really see how your solution improved the former

I know this is old but...
Python is all about clarity (arguably, all languages should be, but python in particular).
We might discuss about the need to create functions just to move along the tree, but variable names are not something that can just be overlooked.

## Tree: Huffman Decoding

You are viewing a single comment's thread. Return to all comments →

`temp`

here is obviously a poor variable name choice. The variable`head`

should be left untouched and a new variable, forexample`current_node`

or just`node`

should be used to traverse the tree down.I don't see how exactly your solution is different. Additionaly,

`temp`

has a local scope and leaves the`root`

un bothered in the original solution. I can't really see how your solution improved the formerI know this is old but... Python is all about clarity (arguably, all languages should be, but python in particular). We might discuss about the need to create functions just to move along the tree, but variable names are not something that can just be overlooked.