title: How to iterate over files in directory in python with respect to size
body: <p>I have a directory with thousands of files, I want to rename them with respect to their sizes, i.e the name of the biggest file is going to be 0001.txt then 0002.txt and so on. To do so iterating over whole directory  with </p>
  
  <pre><code>for filename in files:
      print(filename)
  </code></pre>
  
  <p>is very very costly. Is there an easy an quicker way to do so?</p>