Python Practice › Set Programs › Program 19

Are all elements odd?

EasySet Programs · 19 of 48

Write a Python program to check whether all elements of a set are odd.

Advertisement
Input
{1, 3, 5}, {1, 4}
Output
{1, 3, 5} True
{1, 4} False

Approach

  1. all(x % 2 == 1 for x in s).

Solution

Python
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} False

Learn the concept

New to this topic? Read the lesson, then come back.

More set programs

← All 48 Set Programs

Leave a Comment