nodes: 0, module; 1, function_definition; 2, function_name:best_fit; 3, parameters; 4, block; 5, identifier:li; 6, identifier:value; 7, expression_statement; 8, expression_statement; 9, if_statement; 10, if_statement; 11, comment:"""For a sorted list li, returns the closest item to value"""; 12, assignment; 13, comparison_operator:index in (0, len(li)); 14, block; 15, comparison_operator:li[index] - value < value - li[index-1]; 16, block; 17, else_clause; 18, identifier:index; 19, call; 20, identifier:index; 21, tuple; 22, return_statement; 23, binary_operator:li[index] - value; 24, binary_operator:value - li[index-1]; 25, return_statement; 26, block; 27, identifier:min; 28, argument_list; 29, integer:0; 30, call; 31, identifier:index; 32, subscript; 33, identifier:value; 34, identifier:value; 35, subscript; 36, identifier:index; 37, return_statement; 38, call; 39, binary_operator:len(li) - 1; 40, identifier:len; 41, argument_list; 42, identifier:li; 43, identifier:index; 44, identifier:li; 45, binary_operator:index-1; 46, binary_operator:index-1; 47, identifier:bisect_left; 48, argument_list; 49, call; 50, integer:1; 51, identifier:li; 52, identifier:index; 53, integer:1; 54, identifier:index; 55, integer:1; 56, identifier:li; 57, identifier:value; 58, identifier:len; 59, argument_list; 60, identifier:li
code: def best_fit(li, value):
      """For a sorted list li, returns the closest item to value"""
  
      index = min(bisect_left(li, value), len(li) - 1)
  
      if index in (0, len(li)):
          return index
  
      if li[index] - value < value - li[index-1]:
          return index
      else:
          return index-1