AI engineering glossary · Python core

What is set comprehension?

Set comprehension: A compact expression that builds a set from an iterable, written {expr for item in iterable if cond}. Duplicates are removed automatically, so it is useful for collecting unique values.

Level: intermediateTopic: Python core

Set comprehension: an example

{word.lower() for word in ['Hi', 'HI', 'hello']} gives {'hi', 'hello'}.

Related terms

More Python core terms

Where you learn it

Set comprehension is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.