nodes: 0, module; 1, function_definition; 2, function_name:sorted_exists; 3, parameters; 4, block; 5, identifier:values; 6, identifier:x; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, return_statement; 12, comment:"""
      For list, values, returns the insert position for item x and whether the item already exists in the list. This
      allows one function call to return either the index to overwrite an existing value in the list, or the index to
      insert a new item in the list and keep the list in sorted order.
  
      :param values: list
      :param x: item
      :return: (exists, index) tuple
      """; 13, assignment; 14, assignment; 15, assignment; 16, expression_list; 17, identifier:i; 18, call; 19, identifier:j; 20, call; 21, identifier:exists; 22, comparison_operator:x in values[i:j]; 23, identifier:exists; 24, identifier:i; 25, identifier:bisect_left; 26, argument_list; 27, identifier:bisect_right; 28, argument_list; 29, identifier:x; 30, subscript; 31, identifier:values; 32, identifier:x; 33, identifier:values; 34, identifier:x; 35, identifier:values; 36, slice; 37, identifier:i; 38, identifier:j
code: def sorted_exists(values, x):
      """
      For list, values, returns the insert position for item x and whether the item already exists in the list. This
      allows one function call to return either the index to overwrite an existing value in the list, or the index to
      insert a new item in the list and keep the list in sorted order.
  
      :param values: list
      :param x: item
      :return: (exists, index) tuple
      """
      i = bisect_left(values, x)
      j = bisect_right(values, x)
      exists = x in values[i:j]
      return exists, i