code: def task_states_predicate(service_name, expected_task_count, expected_task_states):
      
      try:
          tasks = get_service_tasks(service_name)
      except (DCOSConnectionError, DCOSHTTPException):
          tasks = []
      matching_tasks = []
      other_tasks = []
      for t in tasks:
          name = t.get('name', 'UNKNOWN_NAME')
          state = t.get('state', None)
          if state and state in expected_task_states:
              matching_tasks.append(name)
          else:
              other_tasks.append('{}={}'.format(name, state))
      print('expected {} tasks in {}:\n- {} in expected {}: {}\n- {} in other states: {}'.format(
          expected_task_count, ', '.join(expected_task_states),
          len(matching_tasks), ', '.join(expected_task_states), ', '.join(matching_tasks),
          len(other_tasks), ', '.join(other_tasks)))
      return len(matching_tasks) >= expected_task_count
docs: Returns whether the provided service_names's tasks have expected_task_count tasks
          in any of expected_task_states. For example, if service 'foo' has 5 tasks which are
          TASK_STAGING or TASK_RUNNING.
  
          :param service_name: the service name
          :type service_name: str
          :param expected_task_count: the number of tasks which should have an expected state
          :type expected_task_count: int
          :param expected_task_states: the list states to search for among the service's tasks
          :type expected_task_states: [str]
  
          :return: True if expected_task_count tasks have any of expected_task_states, False otherwise
          :rtype: bool