nodes: 0, module; 1, function_definition; 2, function_name:print_; 3, parameters; 4, block; 5, identifier:rows; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, expression_statement; 11, for_statement; 12, comment:# input validation; 13, expression_statement; 14, if_statement; 15, expression_statement; 16, if_statement; 17, comment:# sort rows; 18, if_statement; 19, comment:# limit rows; 20, expression_statement; 21, for_statement; 22, comment:# print rows; 23, expression_statement; 24, expression_statement; 25, identifier:limit; 26, integer:15; 27, identifier:sort; 28, string; 29, identifier:order; 30, string; 31, comment:"""Print the rows as a summary.
  
      Keyword arguments:
      limit -- the maximum number of elements to be listed
      sort  -- sort elements by 'size', 'type', or '#'
      order -- sort 'ascending' or 'descending'
      """; 32, assignment; 33, identifier:row; 34, identifier:rows; 35, block; 36, assignment; 37, comparison_operator:sort not in sortby; 38, block; 39, assignment; 40, comparison_operator:order not in orders; 41, block; 42, comparison_operator:sortby.index(sort) == 0; 43, block; 44, else_clause; 45, assignment; 46, identifier:row; 47, identifier:localrows; 48, block; 49, call; 50, call; 51, string_content:size; 52, string_content:descending; 53, identifier:localrows; 54, list; 55, expression_statement; 56, identifier:sortby; 57, list; 58, identifier:sort; 59, identifier:sortby; 60, raise_statement; 61, identifier:orders; 62, list; 63, identifier:order; 64, identifier:orders; 65, raise_statement; 66, call; 67, integer:0; 68, if_statement; 69, block; 70, identifier:localrows; 71, subscript; 72, expression_statement; 73, attribute; 74, argument_list; 75, identifier:_print_table; 76, argument_list; 77, call; 78, string; 79, string; 80, string; 81, call; 82, string; 83, string; 84, call; 85, attribute; 86, argument_list; 87, comparison_operator:order == "ascending"; 88, block; 89, elif_clause; 90, if_statement; 91, identifier:localrows; 92, slice; 93, assignment; 94, identifier:localrows; 95, identifier:insert; 96, integer:0; 97, list; 98, identifier:localrows; 99, attribute; 100, argument_list; 101, string_content:type; 102, string_content:#; 103, string_content:size; 104, identifier:ValueError; 105, argument_list; 106, string_content:ascending; 107, string_content:descending; 108, identifier:ValueError; 109, argument_list; 110, identifier:sortby; 111, identifier:index; 112, identifier:sort; 113, identifier:order; 114, string:"ascending"; 115, expression_statement; 116, comparison_operator:order == "descending"; 117, block; 118, comparison_operator:order == "ascending"; 119, block; 120, elif_clause; 121, integer:0; 122, identifier:limit; 123, subscript; 124, call; 125, string:"types"; 126, string:"# objects"; 127, string:"total size"; 128, identifier:localrows; 129, identifier:append; 130, call; 131, binary_operator:"invalid sort, should be one of" + str(sortby); 132, binary_operator:"invalid order, should be one of" + str(orders); 133, call; 134, identifier:order; 135, string:"descending"; 136, expression_statement; 137, identifier:order; 138, string:"ascending"; 139, expression_statement; 140, comparison_operator:order == "descending"; 141, block; 142, identifier:row; 143, integer:2; 144, attribute; 145, argument_list; 146, identifier:list; 147, argument_list; 148, string:"invalid sort, should be one of"; 149, call; 150, string:"invalid order, should be one of"; 151, call; 152, attribute; 153, argument_list; 154, call; 155, call; 156, identifier:order; 157, string:"descending"; 158, expression_statement; 159, identifier:stringutils; 160, identifier:pp; 161, subscript; 162, identifier:row; 163, identifier:str; 164, argument_list; 165, identifier:str; 166, argument_list; 167, identifier:localrows; 168, identifier:sort; 169, keyword_argument; 170, attribute; 171, argument_list; 172, attribute; 173, argument_list; 174, call; 175, identifier:row; 176, integer:2; 177, identifier:sortby; 178, identifier:orders; 179, identifier:key; 180, lambda; 181, identifier:localrows; 182, identifier:sort; 183, keyword_argument; 184, keyword_argument; 185, identifier:localrows; 186, identifier:sort; 187, keyword_argument; 188, attribute; 189, argument_list; 190, lambda_parameters; 191, call; 192, identifier:key; 193, lambda; 194, identifier:reverse; 195, True; 196, identifier:key; 197, lambda; 198, identifier:localrows; 199, identifier:sort; 200, keyword_argument; 201, keyword_argument; 202, identifier:x; 203, identifier:_repr; 204, argument_list; 205, lambda_parameters; 206, call; 207, lambda_parameters; 208, subscript; 209, identifier:key; 210, lambda; 211, identifier:reverse; 212, True; 213, subscript; 214, identifier:x; 215, identifier:_repr; 216, argument_list; 217, identifier:x; 218, identifier:x; 219, call; 220, lambda_parameters; 221, subscript; 222, identifier:x; 223, integer:0; 224, subscript; 225, attribute; 226, argument_list; 227, identifier:x; 228, identifier:x; 229, call; 230, identifier:x; 231, integer:0; 232, identifier:sortby; 233, identifier:index; 234, identifier:sort; 235, attribute; 236, argument_list; 237, identifier:sortby; 238, identifier:index; 239, identifier:sort
code: def print_(rows, limit=15, sort='size', order='descending'):
      """Print the rows as a summary.
  
      Keyword arguments:
      limit -- the maximum number of elements to be listed
      sort  -- sort elements by 'size', 'type', or '#'
      order -- sort 'ascending' or 'descending'
      """
      localrows = []
      for row in rows:
          localrows.append(list(row))
      # input validation
      sortby = ['type', '#', 'size']
      if sort not in sortby:
          raise ValueError("invalid sort, should be one of" + str(sortby))
      orders = ['ascending', 'descending']
      if order not in orders:
          raise ValueError("invalid order, should be one of" + str(orders))
      # sort rows
      if sortby.index(sort) == 0:
          if order == "ascending":
              localrows.sort(key=lambda x: _repr(x[0]))
          elif order == "descending":
              localrows.sort(key=lambda x: _repr(x[0]), reverse=True)
      else:
          if order == "ascending":
              localrows.sort(key=lambda x: x[sortby.index(sort)])
          elif order == "descending":
              localrows.sort(key=lambda x: x[sortby.index(sort)], reverse=True)
      # limit rows
      localrows = localrows[0:limit]
      for row in localrows:
          row[2] = stringutils.pp(row[2])
      # print rows
      localrows.insert(0,["types", "# objects", "total size"])
      _print_table(localrows)