Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Python Comprehensions!
You have completed Python Comprehensions!
Preview
A set is another iterable that can be created using comprehension. Let’s dive into its syntax!
The Syntax
# basic
{expression for temp_var in iterable}
# with a conditional
{expression for temp_var in iterable if condition}
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Since a set is so similar to a list,
0:00
the comprehension syntax
is almost identical.
0:01
Here's the syntax for
a list comprehension.
0:06
And here's the syntax for
a set comprehension.
0:10
It's easy to miss, but our square
brackets are now curly brackets.
0:14
Python set syntax uses curly brackets.
0:19
So naturally set comprehension
syntax will also use curly brackets.
0:23
Let's explore set comprehension.
0:29
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up