Jinja List Comprehension
Practice writing list comprehension, using Jinja, to create a new list from existing list data
Last updated
Practice writing list comprehension, using Jinja, to create a new list from existing list data
Last updated
Feedback
โฌ๏ธ CannyCopyright ยฉ 2024 Rewst
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 ]}}
Practice the list comprehension exercises included in the "Lunch Menu" data set:
Go to the previous module:
Go to the next module: