Python Practice › Set Programs › Program 18
Are all elements even?
Write a Python program to check whether all elements of a set are even.
Input
{2, 4, 6}, {2, 3}Output
{2, 4, 6} True
{2, 3} FalseApproach
all(x % 2 == 0 for x in s).
Solution
for s in [{2, 4, 6}, {2, 3}]: print(s, all(x % 2 == 0 for x in s))Output
{2, 4, 6} True
{2, 3} FalseLearn the concept
New to this topic? Read the lesson, then come back.