title: How to write a tree class where nodes can be accessed by position?
body: <p>I aim to write a class representing a general tree where nodes can be accessed by giving positions given that new nodes can be added as child to existing and so on.Also positional access has to be written in O(1) time. So far I have decided to write a node and a tree class. Node class for starters is as follows:</p>
  
  <pre><code>class node:
      def __init__(self,data):
          self.data=data
          self.children=[]
      def __str__(self):
          return str(self.data)
      def add_child(self,n,pos=-1)#pos describes position of new child
          if not pos:
              pos=len(self.children)
          if not type(n)==type(node()):
              n=node(n)
          self.children.insert(n)
  </code></pre>
  
  <p>Positional access means that in following tree:</p>
  
  <pre><code>                  1
               2         3
             4   5         6
  </code></pre>
  
  <p>position 1 has value 1, position 2 has value 2 and so on?</p>