Hi everyone,(adsbygoogle = window.adsbygoogle || []).push({});

I'm trying to implement the level-order for a binary tree with python (http://en.wikipedia.org/wiki/Tree_traversal)

I wrote a first function bst that takes two arguments (integers a and b) and returns a binary tree with nodes a+b, a-b,a*b and a//b (when allowed)

I tested this function and it seems to work.

The problem I face is with my level-order function which takes a tree as an argument.

I tried to use a queue here in order to get the level order.

The problem is, when I call this function (on python shell), the following error is raised:

line 96, in level_order

cleft=curr['left']

KeyError: 'left'

I tried to change a little bit my program to identify where this error comes from: I returned curr: no problem, I then returned curr['left'] and still no problem...

If anyone has an idea...

**Physics Forums | Science Articles, Homework Help, Discussion**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Key error on python

Can you offer guidance or do you also need help?

Draft saved
Draft deleted

**Physics Forums | Science Articles, Homework Help, Discussion**