title: Over-riding os.walk to return a generator object as the third item
body: <p>While checking the efficiency of <code>os.walk</code>, I created <code>6,00,000</code> files with the string <code>Hello &lt;number&gt;</code> <em>(where number is just a number indicating the number of the file in the directory)</em>, e.g. the contents of the files in the directory would look like:-</p>
  
  <pre><code>File Name | Contents
  1.txt     | Hello 1
  2.txt     | Hello 2
  .
  .
  600000.txt|Hello 600000
  </code></pre>
  
  <p>Now, I ran the following code:-</p>
  
  <pre><code>a= os.walk(os.path.join(os.getcwd(),'too_many_same_type_files')) ## Here, I am just passing the actual path where those 6,00,000 txt files are present
  print a.next()
  </code></pre>
  
  <hr>
  
  <p>The problem what I felt was that the <code>a.next()</code> takes too much time and memory, because the 3rd item that <code>a.next()</code> would return is the list of files in the directory <em>(which has 600000 items)</em>. So, I am trying to figure out a way to reduce the space complexity <em>(at least)</em> by somehow making <code>a.next()</code> to return a generator object as the 3rd item of the tuple, instead of list of file names.</p>
  
  <p>Would that be a good idea to reduce the space complexity?</p>