title: how to use iterator in recursive function in python?
body: <p>I want to convert my code such that I don't have to use an extra variable (i.e, s in the example below). I know that there is a way to use iterator but I don't know how. Can somebody help? Thanks a bunch.</p>
  
  <pre><code>from numbers import Number
  
  a = [[[1,2],[3,4]],[[5,6],[7,8]]]
  
  
  def trav(root,s):
      if isinstance(root,Number):
          print(str(root) + " -&gt; " + s)
      else:
          s = s + "0"
          trav(root[0],s)
          s = s[:-1]
  
          s = s + "1"
          trav(root[1],s)
          s = s[:-1]
  
  s = ""
  trav(a,s)
  </code></pre>