nodes: 0, module; 1, function_definition; 2, function_name:_aggregate; 3, parameters; 4, block; 5, identifier:data; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, if_statement; 11, expression_statement; 12, if_statement; 13, expression_statement; 14, if_statement; 15, return_statement; 16, identifier:norm; 17, True; 18, identifier:sort_by; 19, string; 20, identifier:keys; 21, None; 22, string; 23, identifier:keys; 24, block; 25, else_clause; 26, assignment; 27, comparison_operator:sort_by == 'value'; 28, block; 29, else_clause; 30, assignment; 31, identifier:norm; 32, block; 33, else_clause; 34, expression_list; 35, string_content:value; 36, string_content:Counts the number of occurances of each item in 'data'.
  
      Inputs
      data: a list of values.
      norm: normalize the resulting counts (as percent)
      sort_by: how to sort the retured data. Options are 'value' and 'count'.
  
      Output
      a non-redundant list of values (from 'data') and a list of counts.; 37, expression_statement; 38, for_statement; 39, block; 40, identifier:vals; 41, list_comprehension; 42, identifier:sort_by; 43, string; 44, expression_statement; 45, block; 46, identifier:xs; 47, list_comprehension; 48, expression_statement; 49, expression_statement; 50, expression_statement; 51, block; 52, identifier:xs; 53, identifier:ys; 54, assignment; 55, identifier:d; 56, identifier:data; 57, block; 58, expression_statement; 59, for_statement; 60, tuple; 61, for_in_clause; 62, string_content:value; 63, call; 64, expression_statement; 65, subscript; 66, for_in_clause; 67, assignment; 68, assignment; 69, assignment; 70, expression_statement; 71, identifier:vdict; 72, dictionary_comprehension; 73, if_statement; 74, assignment; 75, identifier:d; 76, identifier:data; 77, block; 78, identifier:k; 79, identifier:v; 80, pattern_list; 81, call; 82, attribute; 83, argument_list; 84, call; 85, identifier:v; 86, integer:0; 87, identifier:v; 88, identifier:vals; 89, identifier:raw_y; 90, list_comprehension; 91, identifier:total_y; 92, call; 93, identifier:ys; 94, list_comprehension; 95, assignment; 96, pair; 97, for_in_clause; 98, comparison_operator:d in keys; 99, block; 100, identifier:vdict; 101, dictionary; 102, expression_statement; 103, identifier:k; 104, identifier:v; 105, attribute; 106, argument_list; 107, identifier:vals; 108, identifier:sort; 109, keyword_argument; 110, attribute; 111, argument_list; 112, subscript; 113, for_in_clause; 114, identifier:sum; 115, argument_list; 116, binary_operator:100. * y / total_y; 117, for_in_clause; 118, identifier:ys; 119, list_comprehension; 120, identifier:k; 121, integer:0; 122, identifier:k; 123, identifier:keys; 124, identifier:d; 125, identifier:keys; 126, expression_statement; 127, assignment; 128, identifier:vdict; 129, identifier:items; 130, identifier:key; 131, lambda; 132, identifier:vals; 133, identifier:sort; 134, keyword_argument; 135, identifier:v; 136, integer:1; 137, identifier:v; 138, identifier:vals; 139, identifier:raw_y; 140, binary_operator:100. * y; 141, identifier:total_y; 142, identifier:y; 143, identifier:raw_y; 144, subscript; 145, for_in_clause; 146, augmented_assignment; 147, subscript; 148, conditional_expression:vdict[d] + 1 if d in vdict else 1; 149, lambda_parameters; 150, subscript; 151, identifier:key; 152, lambda; 153, float:100.; 154, identifier:y; 155, identifier:v; 156, integer:1; 157, identifier:v; 158, identifier:vals; 159, subscript; 160, integer:1; 161, identifier:vdict; 162, identifier:d; 163, binary_operator:vdict[d] + 1; 164, comparison_operator:d in vdict; 165, integer:1; 166, identifier:x; 167, identifier:x; 168, integer:0; 169, lambda_parameters; 170, subscript; 171, identifier:vdict; 172, identifier:d; 173, subscript; 174, integer:1; 175, identifier:d; 176, identifier:vdict; 177, identifier:x; 178, identifier:x; 179, integer:1; 180, identifier:vdict; 181, identifier:d
code: def _aggregate(data, norm=True, sort_by='value', keys=None):
      '''
      Counts the number of occurances of each item in 'data'.
  
      Inputs
      data: a list of values.
      norm: normalize the resulting counts (as percent)
      sort_by: how to sort the retured data. Options are 'value' and 'count'.
  
      Output
      a non-redundant list of values (from 'data') and a list of counts.
      '''
      if keys:
          vdict = {k: 0 for k in keys}
          for d in data:
              if d in keys:
                  vdict[d] += 1
      else:
          vdict = {}
          for d in data:
              vdict[d] = vdict[d] + 1 if d in vdict else 1
      vals = [(k, v) for k, v in vdict.items()]
      if sort_by == 'value':
          vals.sort(key=lambda x: x[0])
      else:
          vals.sort(key=lambda x: x[1])
      xs = [v[0] for v in vals]
      if norm:
          raw_y = [v[1] for v in vals]
          total_y = sum(raw_y)
          ys = [100. * y / total_y for y in raw_y]
      else:
          ys = [v[1] for v in vals]
      return xs, ys