"Build a Simple Android App with Kotlin" was retired on July 14, 2025.
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!
We’ve just learned how to turn simple loops into a 1-line list comprehension. But what about loops that have conditional if/else blocks? List comprehension can handle that too!
The Syntax
# Condition affects the list
[expression for temp_var in iterable if condition]
# Condition affects the expression
[expression if condition else expression for temp_var in iterable]
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
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