nodes: 0, module; 1, function_definition; 2, function_name:nlargest; 3, parameters; 4, block; 5, identifier:n; 6, identifier:iterable; 7, default_parameter; 8, expression_statement; 9, comment:# Short-cut for n==1 is to use max(); 10, if_statement; 11, comment:# When n>=size, it's faster to use sorted(); 12, try_statement; 13, comment:# When key is none, use simpler decoration; 14, if_statement; 15, comment:# General case, slowest method; 16, expression_statement; 17, expression_statement; 18, if_statement; 19, expression_statement; 20, expression_statement; 21, expression_statement; 22, expression_statement; 23, for_statement; 24, expression_statement; 25, return_statement; 26, identifier:key; 27, None; 28, comment:"""Find the n largest elements in a dataset.
  
      Equivalent to:  sorted(iterable, key=key, reverse=True)[:n]
      """; 29, comparison_operator:n == 1; 30, block; 31, block; 32, except_clause; 33, else_clause; 34, comparison_operator:key is None; 35, block; 36, assignment; 37, assignment; 38, not_operator; 39, block; 40, call; 41, assignment; 42, assignment; 43, assignment; 44, identifier:elem; 45, identifier:it; 46, block; 47, call; 48, list_comprehension; 49, identifier:n; 50, integer:1; 51, expression_statement; 52, expression_statement; 53, if_statement; 54, return_statement; 55, expression_statement; 56, tuple; 57, block; 58, block; 59, identifier:key; 60, None; 61, expression_statement; 62, expression_statement; 63, if_statement; 64, expression_statement; 65, expression_statement; 66, expression_statement; 67, expression_statement; 68, for_statement; 69, expression_statement; 70, return_statement; 71, identifier:it; 72, call; 73, identifier:result; 74, list_comprehension; 75, identifier:result; 76, return_statement; 77, identifier:heapify; 78, argument_list; 79, identifier:top; 80, subscript; 81, identifier:order; 82, unary_operator; 83, identifier:_heapreplace; 84, identifier:heapreplace; 85, expression_statement; 86, if_statement; 87, attribute; 88, argument_list; 89, subscript; 90, for_in_clause; 91, assignment; 92, assignment; 93, comparison_operator:key is None; 94, block; 95, else_clause; 96, conditional_expression:[] if result is sentinel else [result]; 97, assignment; 98, identifier:TypeError; 99, identifier:AttributeError; 100, pass_statement; 101, if_statement; 102, assignment; 103, assignment; 104, not_operator; 105, block; 106, call; 107, assignment; 108, assignment; 109, assignment; 110, identifier:elem; 111, identifier:it; 112, block; 113, call; 114, list_comprehension; 115, identifier:iter; 116, argument_list; 117, tuple; 118, for_in_clause; 119, identifier:result; 120, identifier:result; 121, subscript; 122, integer:0; 123, identifier:n; 124, assignment; 125, comparison_operator:top < k; 126, block; 127, identifier:result; 128, identifier:sort; 129, keyword_argument; 130, identifier:r; 131, integer:2; 132, identifier:r; 133, identifier:result; 134, identifier:it; 135, call; 136, identifier:sentinel; 137, call; 138, identifier:key; 139, None; 140, expression_statement; 141, block; 142, list; 143, comparison_operator:result is sentinel; 144, list; 145, identifier:size; 146, call; 147, comparison_operator:n >= size; 148, block; 149, identifier:it; 150, call; 151, identifier:result; 152, list_comprehension; 153, identifier:result; 154, return_statement; 155, identifier:heapify; 156, argument_list; 157, identifier:top; 158, subscript; 159, identifier:order; 160, unary_operator; 161, identifier:_heapreplace; 162, identifier:heapreplace; 163, if_statement; 164, attribute; 165, argument_list; 166, subscript; 167, for_in_clause; 168, identifier:iterable; 169, call; 170, identifier:i; 171, identifier:elem; 172, pattern_list; 173, call; 174, identifier:result; 175, integer:0; 176, identifier:k; 177, call; 178, identifier:top; 179, identifier:k; 180, expression_statement; 181, expression_statement; 182, expression_statement; 183, identifier:reverse; 184, True; 185, identifier:iter; 186, argument_list; 187, identifier:object; 188, argument_list; 189, assignment; 190, expression_statement; 191, identifier:result; 192, identifier:sentinel; 193, identifier:result; 194, identifier:len; 195, argument_list; 196, identifier:n; 197, identifier:size; 198, return_statement; 199, identifier:iter; 200, argument_list; 201, tuple; 202, for_in_clause; 203, identifier:result; 204, identifier:result; 205, subscript; 206, integer:0; 207, identifier:n; 208, comparison_operator:top < elem; 209, block; 210, identifier:result; 211, identifier:sort; 212, keyword_argument; 213, identifier:r; 214, integer:0; 215, identifier:r; 216, identifier:result; 217, identifier:key; 218, argument_list; 219, identifier:i; 220, identifier:elem; 221, identifier:zip; 222, argument_list; 223, identifier:key; 224, argument_list; 225, call; 226, assignment; 227, augmented_assignment; 228, identifier:iterable; 229, identifier:result; 230, call; 231, assignment; 232, identifier:iterable; 233, subscript; 234, identifier:iterable; 235, identifier:elem; 236, identifier:i; 237, pattern_list; 238, call; 239, identifier:result; 240, integer:0; 241, identifier:top; 242, identifier:elem; 243, expression_statement; 244, expression_statement; 245, expression_statement; 246, identifier:reverse; 247, True; 248, identifier:elem; 249, call; 250, identifier:it; 251, identifier:elem; 252, identifier:_heapreplace; 253, argument_list; 254, identifier:top; 255, subscript; 256, identifier:order; 257, integer:1; 258, identifier:max; 259, argument_list; 260, identifier:result; 261, call; 262, call; 263, slice; 264, identifier:i; 265, identifier:elem; 266, identifier:zip; 267, argument_list; 268, call; 269, assignment; 270, augmented_assignment; 271, identifier:range; 272, argument_list; 273, identifier:result; 274, tuple; 275, subscript; 276, integer:0; 277, identifier:it; 278, keyword_argument; 279, identifier:max; 280, argument_list; 281, identifier:sorted; 282, argument_list; 283, identifier:n; 284, call; 285, identifier:it; 286, identifier:_heapreplace; 287, argument_list; 288, identifier:top; 289, subscript; 290, identifier:order; 291, integer:1; 292, integer:0; 293, unary_operator; 294, unary_operator; 295, identifier:k; 296, identifier:order; 297, identifier:elem; 298, identifier:result; 299, integer:0; 300, identifier:default; 301, identifier:sentinel; 302, identifier:it; 303, keyword_argument; 304, keyword_argument; 305, identifier:iterable; 306, keyword_argument; 307, keyword_argument; 308, identifier:range; 309, argument_list; 310, identifier:result; 311, tuple; 312, subscript; 313, integer:0; 314, identifier:n; 315, integer:1; 316, identifier:default; 317, identifier:sentinel; 318, identifier:key; 319, identifier:key; 320, identifier:key; 321, identifier:key; 322, identifier:reverse; 323, True; 324, integer:0; 325, unary_operator; 326, unary_operator; 327, identifier:elem; 328, identifier:order; 329, identifier:result; 330, integer:0; 331, identifier:n; 332, integer:1
code: def nlargest(n, iterable, key=None):
      """Find the n largest elements in a dataset.
  
      Equivalent to:  sorted(iterable, key=key, reverse=True)[:n]
      """
  
      # Short-cut for n==1 is to use max()
      if n == 1:
          it = iter(iterable)
          sentinel = object()
          if key is None:
              result = max(it, default=sentinel)
          else:
              result = max(it, default=sentinel, key=key)
          return [] if result is sentinel else [result]
  
      # When n>=size, it's faster to use sorted()
      try:
          size = len(iterable)
      except (TypeError, AttributeError):
          pass
      else:
          if n >= size:
              return sorted(iterable, key=key, reverse=True)[:n]
  
      # When key is none, use simpler decoration
      if key is None:
          it = iter(iterable)
          result = [(elem, i) for i, elem in zip(range(0, -n, -1), it)]
          if not result:
              return result
          heapify(result)
          top = result[0][0]
          order = -n
          _heapreplace = heapreplace
          for elem in it:
              if top < elem:
                  _heapreplace(result, (elem, order))
                  top = result[0][0]
                  order -= 1
          result.sort(reverse=True)
          return [r[0] for r in result]
  
      # General case, slowest method
      it = iter(iterable)
      result = [(key(elem), i, elem) for i, elem in zip(range(0, -n, -1), it)]
      if not result:
          return result
      heapify(result)
      top = result[0][0]
      order = -n
      _heapreplace = heapreplace
      for elem in it:
          k = key(elem)
          if top < k:
              _heapreplace(result, (k, order, elem))
              top = result[0][0]
              order -= 1
      result.sort(reverse=True)
      return [r[2] for r in result]