code: def _least_constraining_values_sorter(problem, assignment, variable, domains):
      '''
      Sort values based on how many conflicts they generate if assigned.
      '''
      # the value that generates less conflicts
      def update_assignment(value):
          new_assignment = deepcopy(assignment)
          new_assignment[variable] = value
          return new_assignment
  
      values = sorted(domains[variable][:],
                      key=lambda v: _count_conflicts(problem, assignment,
                                                     variable, v))
      return valuef _least_constraining_values_sorter(problem, assignment, variable, domains):
      '''
      Sort values based on how many conflicts they generate if assigned.
      '''
      # the value that generates less conflicts
      def update_assignment(value):
          new_assignment = deepcopy(assignment)
          new_assignment[variable] = value
          return new_assignment
  
      values = sorted(domains[variable][:],
                      key=lambda v: _count_conflicts(problem, assignment,
                                                     variable, v))
      return values
docs: Sort values based on how many conflicts they generate if assigned.