Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Check membership in a set

Use a set to perform fast membership checks.

Python practice8 minDictionaries & SetsBeginnerLast updated March 18, 2026

Problem statement

Write a function that checks whether a value is present in a collection. Convert the collection to a set (if it isn't already) and use Python's membership operator (in) to return True or False. This demonstrates using sets for fast membership checks.

Task

Determine whether a value exists in a collection by converting it to a set and using membership testing.

Examples

Value present in a list

Input

([1, 2, 3], 2)

Output

True

2 is in the list, converting to a set keeps 2 and membership check returns True.

Input format

Two arguments: (collection, value). The collection can be a list or a set.

Output format

A boolean: True if value is found, False otherwise.

Constraints

Items are hashable. Comparison uses equality (==).

Samples

Sample 1

Input

([1, 2, 3], 2)

Output

True

2 is present in the collection.