title: Python - order of os.listdir
body: <p>I'm new in Python and I'm working on a script that reads all the files in a directory (which contains only files).
  I know that I can get the files using a loop like this:</p>
  
  <pre><code>for file in os.listdir("my directory"):
  </code></pre>
  
  <p>Or a list of files using this syntax:</p>
  
  <pre><code>files = [f for f in os.listdir("my directory ")]
  </code></pre>
  
  <p>The problem is that I get the files in a completely random order. I solved my problem using a <code>sort</code> command to get my list sorted, but, I am still left wondering:</p>
  
  <p><strong>How does Python sort the files that are returned by the <code>listdir</code> method?</strong></p>