code: def get_filetypes(filelist, path=None, size=os.path.getsize):
      
      path = path or (lambda _: _)
  
      # Get total size for each file extension
      histo = defaultdict(int)
      for entry in filelist:
          ext = os.path.splitext(path(entry))[1].lstrip('.').lower()
          if ext and ext[0] == 'r' and ext[1:].isdigit():
              ext = "rar"
          elif ext == "jpeg":
              ext = "jpg"
          elif ext == "mpeg":
              ext = "mpg"
          histo[ext] += size(entry)
  
      # Normalize values to integer percent
      total = sum(histo.values())
      if total:
          for ext, val in histo.items():
              histo[ext] = int(val * 100.0 / total + .499)
  
      return sorted(zip(histo.values(), histo.keys()), reverse=True)
docs: Get a sorted list of file types and their weight in percent
          from an iterable of file names.
  
          @return: List of weighted file extensions (no '.'), sorted in descending order
          @rtype: list of (weight, filetype)