Jinja List Comprehension
Practice writing list comprehension, using Jinja, to create a new list from existing list data
Module Overview
💡 List comprehension (a special enhancement to "Rewst-flavored Jinja"!) allows you to create a new list from an existing one in a simplified way, without needing to end the code with {% endfor %}
. It consists of three parts:
Output – What do you want in your new list?
For Loop – How do you loop through data in the original list?
Condition (Optional) – Do you need to filter items to include in your new list?
Here's the basic structure:
{{
[ output for output
in CTX.list
if condition ]}}
Video (3:16 Minutes)
Action Items
Practice the list comprehension exercises included in the "Lunch Menu" data set: Lesson Resources
Navigation
Go to the previous module:
Go to the next module:
Last updated