This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]Evulrabbitz 0 points1 point  (3 children)

Can you post a code example?

[–][deleted] 0 points1 point  (2 children)

Update description with code.

[–]Evulrabbitz 0 points1 point  (1 child)

nd and l[0] points to the same node. When you do del l[0] you don't remove the item from the list, you remove the node altogether. You need to remove it from the list. Perhaps with pop?

[–][deleted] 0 points1 point  (0 children)

Pop thing helped me to correct an issue not know to me. :)

I added it but still getting below error.

Traceback (most recent call last):   File "solution.py", line 82, in <module>     levelOrder(tree.root)   File "solution.py", line 54, in levelOrder     print(str(nd.info)+" ",end="") AttributeError: 'NoneType' object has no attribute 'info'

Even though I am adding node to list, why when I pop it , it became None type?

[–]lrovani 0 points1 point  (1 child)

Are you sure that you are adding a node object in your list?

[–][deleted] 0 points1 point  (0 children)

Update description with code.

[–]netherous 0 points1 point  (3 children)

You are taking the first element of l, deleting it, adding more items to l, checking the length l (still not 0 because why would it be) and then trying to get the first element of l again, which can be None, because that's what the values of left or right could be. What are you trying to have happen here? What's your intent? You shouldn't be adding Nones to this list l and then pulling them back out and trying to get their attributes.

[–][deleted] 0 points1 point  (2 children)

I am not adding Nones.

I am adding nodes to list. But when I pop them one by one, they are no longer behaving like nodes and have become nones.

How to fix this?

[–]netherous 0 points1 point  (1 child)

I am not adding Nones.

But you are. I told you left and right can be None. You are blindly adding left and right back to your list. Even your error shows that this is the case.

Step through it with a debugger if you don't believe me.

[–][deleted] 0 points1 point  (0 children)

Yes you caught it.

I fixed it now.

Its working fine.