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.
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.