Python Practice › Set Programs › Program 4

Length of a set

EasySet Programs · 4 of 48

Write a Python program to find the number of items in a set.

Advertisement
Input
{"a", "b", "c", "a"}
Output
3

Approach

  1. len() counts unique items.

Solution

Python
print(len({"a", "b", "c", "a"}))
Output
3

Learn the concept

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

More set programs

← All 48 Set Programs

Leave a Comment