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
Now that you’ve got the theory, let’s work through these examples of loop-to-comprehension together to challenge your new skills!
Resources
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
Now that you've got the theory,
let's put them to practice.
0:00
I've put together seven challenges
that will challenge your new skills,
0:04
open up challengers.pi and
let's have a look.
0:09
Each challenge comes with some
instructions, an expected output,
0:13
a placeholder section to write your
comprehension, and some print statements.
0:17
Let's run the file to see what
these print statements produce.
0:23
Python3 ,7 tab, enter. We'll only
see the last one at the moment, but
0:26
you can see that this placeholder is
where your comprehension output would go.
0:31
All you have to do,
0:38
is write your one line comprehension
in each of these placeholders.
0:40
Challenges 1 and 2,
test your knowledge of list comprehension.
0:44
Challenges 3 and 4,
are all about dictionary comprehension,
0:50
challenges 4 and
6 focus on set comprehension..
0:56
And challenge 7 is a little more involved
and may require some additional research,
1:01
so feel free to crack open your
favorite search engine for this one.
1:06
Some challenges like this one,
provide data in a list or
1:12
dictionary stored in variables.
1:15
To keep your list comprehensions clean,
be sure to refer to the variable
1:18
rather than copying the entire list or
dictionary into your comprehension.
1:22
Pause this video and
give the challenges ago.
1:29
Read the instructions, take your time,
and know that you can always jump back
1:32
to previous videos or
other files in the project files.
1:37
Don't worry if you aren't able to
complete any of these challenges,
1:41
you've just learned about comprehensions,
and
1:45
you'll need time and experience for
this concept to lay down its roots.
1:48
You can always reattempt to these
challenges after watching my solutions, or
1:52
watch the solutions one at a time to see
if my workflow helps you with the next
1:57
challenge.
2:02
You can even check out the answers
in the teacher's notes and
2:04
reverse engineer why they work.
2:07
Be kind to yourself and know that just
by being here you're already setting
2:10
yourself up for success,
I'll see you in a bit
2:14
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