title: How to get only first 50 files from all subdirectories of a directory in Python?
body: <p>I am trying to get first 50 .jpg files from different subdirectories of a particular directory. Till now, I have only succedded in getting the path name of all using the following list of commands:</p>
  
  <pre><code>import os
  import os.path
  
  for dirpath, dirnames, filenames in os.walk("."):
      for filename in [f for f in filenames if f.endswith(".jpg")]:
          print os.path.join(dirpath, filename)
  </code></pre>
  
  <p>Can someone please tell as to how to extract only first 50 files from the subdirectories?</p>