# a def forall(pred, iterable): return all(pred(x) for x in iterable) def exists(pred, iterable): return any(pred(x) for x in iterable) def atleast(n, pred, iterable): return sum(1 for x in iterable if pred(x)) >= n def atmost(n, pred, iterable): return sum(1 for x in iterable if pred(x)) <= n if __name__ == "__main__": lists = [ [], [1], [2,4,6,8], [2,2,2,2,2], [1,1,1,1,1], [1,2,3,4,5], [10,20,30], ] print("2.a") for l in lists: print(f"{l} all even: {forall(lambda x: x % 2 == 0, l)}") print("2.b") for l in lists: print(f"{l} exists value equal to 1: {exists(lambda x: x == 1, l)}") print("2.c") for l in lists: print(f"{l} at least 2 even values: {atleast(2, lambda x: x % 2 == 0, l)}") print("2.d") for l in lists: print(f"{l} at most 2 even values: {atmost(2, lambda x: x % 2 == 0, l)}")