nodes: 0, module; 1, function_definition; 2, function_name:rankdata; 3, parameters; 4, block; 5, identifier:inlist; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, for_statement; 13, return_statement; 14, comment:"""
  Ranks the data in inlist, dealing with ties appropritely.  Assumes
  a 1D inlist.  Adapted from Gary Perlman's |Stat ranksort.
  
  Usage:   rankdata(inlist)
  Returns: a list of length equal to inlist, containing rank scores
  """; 15, assignment; 16, assignment; 17, assignment; 18, assignment; 19, assignment; 20, identifier:i; 21, call; 22, block; 23, identifier:newlist; 24, identifier:n; 25, call; 26, pattern_list; 27, call; 28, identifier:sumranks; 29, integer:0; 30, identifier:dupcount; 31, integer:0; 32, identifier:newlist; 33, binary_operator:[0] * n; 34, identifier:range; 35, argument_list; 36, expression_statement; 37, expression_statement; 38, if_statement; 39, identifier:len; 40, argument_list; 41, identifier:svec; 42, identifier:ivec; 43, identifier:shellsort; 44, argument_list; 45, list; 46, identifier:n; 47, identifier:n; 48, assignment; 49, assignment; 50, boolean_operator; 51, block; 52, identifier:inlist; 53, identifier:inlist; 54, integer:0; 55, identifier:sumranks; 56, binary_operator:sumranks + i; 57, identifier:dupcount; 58, binary_operator:dupcount + 1; 59, comparison_operator:i == n - 1; 60, comparison_operator:svec[i] != svec[i + 1]; 61, expression_statement; 62, for_statement; 63, expression_statement; 64, expression_statement; 65, identifier:sumranks; 66, identifier:i; 67, identifier:dupcount; 68, integer:1; 69, identifier:i; 70, binary_operator:n - 1; 71, subscript; 72, subscript; 73, assignment; 74, identifier:j; 75, call; 76, block; 77, assignment; 78, assignment; 79, identifier:n; 80, integer:1; 81, identifier:svec; 82, identifier:i; 83, identifier:svec; 84, binary_operator:i + 1; 85, identifier:averank; 86, binary_operator:sumranks / float(dupcount) + 1; 87, identifier:range; 88, argument_list; 89, expression_statement; 90, identifier:sumranks; 91, integer:0; 92, identifier:dupcount; 93, integer:0; 94, identifier:i; 95, integer:1; 96, binary_operator:sumranks / float(dupcount); 97, integer:1; 98, binary_operator:i - dupcount + 1; 99, binary_operator:i + 1; 100, assignment; 101, identifier:sumranks; 102, call; 103, binary_operator:i - dupcount; 104, integer:1; 105, identifier:i; 106, integer:1; 107, subscript; 108, identifier:averank; 109, identifier:float; 110, argument_list; 111, identifier:i; 112, identifier:dupcount; 113, identifier:newlist; 114, subscript; 115, identifier:dupcount; 116, identifier:ivec; 117, identifier:j
code: def rankdata(inlist):
      """
  Ranks the data in inlist, dealing with ties appropritely.  Assumes
  a 1D inlist.  Adapted from Gary Perlman's |Stat ranksort.
  
  Usage:   rankdata(inlist)
  Returns: a list of length equal to inlist, containing rank scores
  """
      n = len(inlist)
      svec, ivec = shellsort(inlist)
      sumranks = 0
      dupcount = 0
      newlist = [0] * n
      for i in range(n):
          sumranks = sumranks + i
          dupcount = dupcount + 1
          if i == n - 1 or svec[i] != svec[i + 1]:
              averank = sumranks / float(dupcount) + 1
              for j in range(i - dupcount + 1, i + 1):
                  newlist[ivec[j]] = averank
              sumranks = 0
              dupcount = 0
      return newlist