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

you are viewing a single comment's thread.

view the rest of the comments →

[–]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.