title: How to find out two lists with same structure in python?
body: <p>Define a procedure, same_structure, that takes two inputs. It should output
  <code>True</code> if the lists have the same structure, and <code>False</code>
  otherwise. Two values, p and q have the same structure if:</p>
  
  <pre class="lang-none prettyprint-override"><code>Neither p or q is a list.
  
  Both p and q are lists, they have the same number of elements, and each
  element of p has the same structure as the corresponding element of q.
  </code></pre>
  
  <p>EDIT: To make the picture clear the following are the expected output</p>
  
  <pre><code>same_structure([1, 0, 1], [2, 1, 2])
      ---&gt; True
  same_structure([1, [0], 1], [2, 5, 3])
      ---&gt; False
  same_structure([1, [2, [3, [4, 5]]]], ['a', ['b', ['c', ['d', 'e']]]])
      ---&gt; True
  same_structure([1, [2, [3, [4, 5]]]], ['a', ['b', ['c', ['de']]]])
      ---&gt; False 
  </code></pre>
  
  <p>I thought recursion would be best to solve this problem in python I have come up with the following code but its not working. </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):
          return True
      elif is_list(a) and is_list(b):
          if len(a) == len(b):
              same_structure(a[1:],b[1:])
      else:
          return False
  </code></pre>