Level based Representation of a Binary Tree - load and dump usage

This article is part 2 of the series Level based Representation of a Binary Tree

So, Let's solve the quiz.

As we start the project let's think about the usage of the functions. We want all related functions to reside in the tree package. The user of the package should be able to import the package and start using the dump and load functions

Using tree package
 >>> import tree    
 >>> root = tree.load([0])
 >>> root.right = Node(2,None,None)
 >>> tree.dump(tree) 

To do so follow the following steps :

First, let's create the "tree" under the project root directory

Now create the "tree/node.py" and define the Node class.

 class Node:
     def __init__(self,data : int ,left : 'Node' , right : 'Node'):
         self.data  = data
         self.left  = left
         self.right = right

Now, create the "tree/actions.py" and create the load and dump stubs.

 from typing import List,Union
 from .node import Node

 def load( data : List[Union[int,None]] ) -> Node :
     return None

 def dump( tree : Node ) -> List[Union[int,None]] :
     return None

Now, let's convert the "tree" directory to a package, by creating "tree/__init__.py". This file will expose the the Node class and the actions to the outside world.

Using tree package
 from .node import Node
 from .actions import load
 from .actions import dump

Let's see the directory structure so far:

Directory structure so far
   ├── tree 
         ├── __init__.py
         ├── node.py
         ├── actions.py
In the next part, we create a test case for load function.