title: Displaying a tree in ASCII
body: <p>As a time-pass activity, I decided to implement a <a href="http://en.wikipedia.org/wiki/Tree_%28data_structure%29" rel="noreferrer">Tree</a>(like) structure in python.<br>
  I implemented a <code>Node</code> class (which alone serves the purpose here) like so:</p>
  
  <pre><code>class Node:
      def __init__(self, name, parent, *data):
          self.name = name
          self.parent = parent
          self.data = data
          self.children = []
          self.is_root = False
  
      def __repr__(self):
          return 'Node '+repr(self.name)
  
      def dic(self):
          retval = {self:[]}
          for i in self.children:
              retval[self].append(i.dic())
          return retval
  
      def display(self): # Here
          pass
  
      def has_children(self):
          return bool(self.children)
  
      def get_parent(self):
          return self.parent
  
      def add_child(self, name, *data):
          child = Node(name, self,*data)
          self.children.append(child)
          return child
  </code></pre>
  
  <p>As you can see the <code>display</code> function is not implemented.<br>
  Here's an example tree.</p>
  
  <pre><code>A = Node('A',Node)
  A.is_root = True
  B = A.add_child('B')
  D = B.add_child('D')
  C = A.add_child('C')
  E = C.add_child('E')
  F = C.add_child('F')
  G = C.add_child('G')
  </code></pre>
  
  <p>Here's some sample output for <code>display</code>.</p>
  
  <pre><code>&gt;&gt;&gt; A.display()
      A
    +-^-+
    B   C
    | +-+-+
    D E F G
  &gt;&gt;&gt; C.display()
     C
   +-+-+
   E F G
  </code></pre>
  
  <p>In the shortest form,<br>
  <strong>How can I "build" an ASCII tree (like above) from the Node class??</strong></p>
  
  <p>In a longer form,<br>
  The "Logic" of printing is:</p>
  
  <ol>
  <li>When there is only one child, <code>|</code> is put above the child. (D)</li>
  <li>Else, Every child has a <code>+</code> above it, (B,C,E,F)</li>
  <li>When there are even no. of children, <code>^</code> is put below the parent. (A)</li>
  <li>Else, (there are odd no. of children) <code>+</code> is put below the parent. (C)</li>
  </ol>
  
  <p>I have been thinking of starting from below. 
  I realized that there has to be a call to the each of the children, but have been unable to implement anything (of that sorts or otherwise) that gave anything close to it.</p>