title: How to properly use recursion in this (simple) python procedure?
body: <p>guys, I wrote a function to test if two inputs (a and b) have the same data structure, this way:</p>
  
  <pre><code>print same_structure([1, 0, 1], [a, b, c])
  #&gt;&gt;&gt; True
  #print same_structure([1, [0], 1], [2, 5, 3])
  &gt;&gt;&gt; False
  #print same_structure([1, [2, [3, [4, 5]]]], ['a', ['b', ['c', ['d', 'e']]]])
  &gt;&gt;&gt; True  
  #print same_structure([1, [2, [3, [4, 5]]]], ['a', ['b', ['c', ['de']]]])
  &gt;&gt;&gt; False
  </code></pre>
  
  <p>This function has (in my implementation) to use recursion. I'm very beginner in recursion and I still have difficulty on thinking recursively. In addition, to avoid cheating the answer, I want to use my own (messy) code and through it learn to use the recursive call (using this code line: 'same_structure return (a [i], b [e])' properly). Could someone show how to properly use the recursion in code below?
  Thanks in advance for any help!!!</p>
  
  <pre><code>def is_list(p):
  return isinstance(p, list)
  
  def same_structure(a,b):
      if not is_list(a) and not is_list(b):
          print '#1'
          return True
      else:
          if is_list(a) and is_list(b):
              print '#2'
              if len(a) != len(b):
                  print '#3'
                  return False
              if len(a) == len(b):
                  print '#4'
                  for e in range(len(a)):
                      print 'e = ', e, 'a[e]= ', a[e], 'b[e]=', b[e]
                      return same_structure(a[e], b[e])           
          else:
              return False
  </code></pre>