Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Key error on python

  1. Dec 25, 2011 #1
    Hi everyone,
    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
    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...

    Attached Files:

  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted

Similar Discussions: Key error on python
  1. Error in python book? (Replies: 3)

  2. Error on Python (Replies: 9)