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