nodes: 0, module; 1, function_definition; 2, function_name:get_filetypes; 3, parameters; 4, block; 5, identifier:filelist; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, comment:# Get total size for each file extension; 11, expression_statement; 12, for_statement; 13, comment:# Normalize values to integer percent; 14, expression_statement; 15, if_statement; 16, return_statement; 17, identifier:path; 18, None; 19, identifier:size; 20, attribute; 21, comment:""" 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)
      """; 22, assignment; 23, assignment; 24, identifier:entry; 25, identifier:filelist; 26, block; 27, assignment; 28, identifier:total; 29, block; 30, call; 31, attribute; 32, identifier:getsize; 33, identifier:path; 34, boolean_operator; 35, identifier:histo; 36, call; 37, expression_statement; 38, if_statement; 39, expression_statement; 40, identifier:total; 41, call; 42, for_statement; 43, identifier:sorted; 44, argument_list; 45, identifier:os; 46, identifier:path; 47, identifier:path; 48, parenthesized_expression; 49, identifier:defaultdict; 50, argument_list; 51, assignment; 52, boolean_operator; 53, block; 54, elif_clause; 55, elif_clause; 56, augmented_assignment; 57, identifier:sum; 58, argument_list; 59, pattern_list; 60, call; 61, block; 62, call; 63, keyword_argument; 64, lambda; 65, identifier:int; 66, identifier:ext; 67, call; 68, boolean_operator; 69, call; 70, expression_statement; 71, comparison_operator:ext == "jpeg"; 72, block; 73, comparison_operator:ext == "mpeg"; 74, block; 75, subscript; 76, call; 77, call; 78, identifier:ext; 79, identifier:val; 80, attribute; 81, argument_list; 82, expression_statement; 83, identifier:zip; 84, argument_list; 85, identifier:reverse; 86, True; 87, lambda_parameters; 88, identifier:_; 89, attribute; 90, argument_list; 91, identifier:ext; 92, comparison_operator:ext[0] == 'r'; 93, attribute; 94, argument_list; 95, assignment; 96, identifier:ext; 97, string:"jpeg"; 98, expression_statement; 99, identifier:ext; 100, string:"mpeg"; 101, expression_statement; 102, identifier:histo; 103, identifier:ext; 104, identifier:size; 105, argument_list; 106, attribute; 107, argument_list; 108, identifier:histo; 109, identifier:items; 110, assignment; 111, call; 112, call; 113, identifier:_; 114, call; 115, identifier:lower; 116, subscript; 117, string; 118, subscript; 119, identifier:isdigit; 120, identifier:ext; 121, string:"rar"; 122, assignment; 123, assignment; 124, identifier:entry; 125, identifier:histo; 126, identifier:values; 127, subscript; 128, call; 129, attribute; 130, argument_list; 131, attribute; 132, argument_list; 133, attribute; 134, argument_list; 135, identifier:ext; 136, integer:0; 137, string_content:r; 138, identifier:ext; 139, slice; 140, identifier:ext; 141, string:"jpg"; 142, identifier:ext; 143, string:"mpg"; 144, identifier:histo; 145, identifier:ext; 146, identifier:int; 147, argument_list; 148, identifier:histo; 149, identifier:values; 150, identifier:histo; 151, identifier:keys; 152, subscript; 153, identifier:lstrip; 154, string; 155, integer:1; 156, binary_operator:val * 100.0 / total + .499; 157, call; 158, integer:1; 159, string_content:.; 160, binary_operator:val * 100.0 / total; 161, float:.499; 162, attribute; 163, argument_list; 164, binary_operator:val * 100.0; 165, identifier:total; 166, attribute; 167, identifier:splitext; 168, call; 169, identifier:val; 170, float:100.0; 171, identifier:os; 172, identifier:path; 173, identifier:path; 174, argument_list; 175, identifier:entry
code: def get_filetypes(filelist, path=None, size=os.path.getsize):
      """ 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)
      """
      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)