title: Changing recursive function to iterative function in Python
body: <p>I read that you can turn any recursive function into an iterative function. I have an iterative function to obtain values from the nested list shown here:</p>
  
  <pre><code>filled_list = [1,2,3,[1,2,3,[1,2,3,[1,2,3,4]]]]
  </code></pre>
  
  <p>Recursive Function:</p>
  
  <pre><code>def recursive_list(value, count):
      x, _, _, _d = value
      if not count%2:
          yield x
      yield from ([] if not isinstance(_d, list) else recursive_list(_d, count+2))
  x = recursive_list(filled_list, 0)
  print(list(x), "Parsing a list recursively.")
  </code></pre>
  
  <p>Output: [1, 1, 1, 1] Parsing a list recursively.</p>
  
  <p>I am trying to turn this into an iterative function. Here is what I have so far. I am stuck and don't understand how to iterate through each nested list until I reach the end. The output should be the same as the recursive function.</p>
  
  <pre><code>def iterative_list(value):
      value_list = []
      for a in value:
          for _d in value:
              a, _, _, _d = value
              y, _, _, _d = _d
              value_list.append(a)
              value_list.append(y)
      return value_list
  z = iterative_list(filled_list)
  print(z, "Parsing a list iteratively.")
  </code></pre>