nodes: 0, module; 1, function_definition; 2, function_name:_binary_insert; 3, parameters; 4, block; 5, identifier:lst; 6, identifier:elem; 7, identifier:key; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, if_statement; 12, if_statement; 13, while_statement; 14, expression_statement; 15, identifier:lo; 16, integer:0; 17, identifier:hi; 18, None; 19, comment:"""
          Insert an element into a sorted list, and keep the list sorted.
  
          The major difference from bisect.bisect_left is that this function supports a key method, so user doesn't have
          to create the key array for each insertion.
  
          :param list lst: The list. Must be pre-ordered.
          :param object element: An element to insert into the list.
          :param func key: A method to get the key for each element in the list.
          :param int lo: Lower bound of the search.
          :param int hi: Upper bound of the search.
          :return: None
          """; 20, comparison_operator:lo < 0; 21, block; 22, comparison_operator:hi is None; 23, block; 24, comparison_operator:lo < hi; 25, block; 26, call; 27, identifier:lo; 28, integer:0; 29, raise_statement; 30, identifier:hi; 31, None; 32, expression_statement; 33, identifier:lo; 34, identifier:hi; 35, expression_statement; 36, if_statement; 37, attribute; 38, argument_list; 39, call; 40, assignment; 41, assignment; 42, comparison_operator:key(lst[mid]) < key(elem); 43, block; 44, else_clause; 45, identifier:lst; 46, identifier:insert; 47, identifier:lo; 48, identifier:elem; 49, identifier:ValueError; 50, argument_list; 51, identifier:hi; 52, call; 53, identifier:mid; 54, binary_operator:(lo + hi) // 2; 55, call; 56, call; 57, expression_statement; 58, block; 59, string:"lo must be a non-negative number"; 60, identifier:len; 61, argument_list; 62, parenthesized_expression; 63, integer:2; 64, identifier:key; 65, argument_list; 66, identifier:key; 67, argument_list; 68, assignment; 69, expression_statement; 70, identifier:lst; 71, binary_operator:lo + hi; 72, subscript; 73, identifier:elem; 74, identifier:lo; 75, binary_operator:mid + 1; 76, assignment; 77, identifier:lo; 78, identifier:hi; 79, identifier:lst; 80, identifier:mid; 81, identifier:mid; 82, integer:1; 83, identifier:hi; 84, identifier:mid
code: def _binary_insert(lst, elem, key, lo=0, hi=None):
          """
          Insert an element into a sorted list, and keep the list sorted.
  
          The major difference from bisect.bisect_left is that this function supports a key method, so user doesn't have
          to create the key array for each insertion.
  
          :param list lst: The list. Must be pre-ordered.
          :param object element: An element to insert into the list.
          :param func key: A method to get the key for each element in the list.
          :param int lo: Lower bound of the search.
          :param int hi: Upper bound of the search.
          :return: None
          """
  
          if lo < 0:
              raise ValueError("lo must be a non-negative number")
  
          if hi is None:
              hi = len(lst)
  
          while lo < hi:
              mid = (lo + hi) // 2
              if key(lst[mid]) < key(elem):
                  lo = mid + 1
              else:
                  hi = mid
  
          lst.insert(lo, elem)