---
title: "Show some equivalent list comprehensions in filter examples · ..."
description: "!https://github.com/pallets/jinja/issues/1068"
date: 2023-12-15
published: true
tags:
  - dev
  - python
  - thought
  - webdev
template: link
---


<div class="embed-card embed-card-external">
  <a href="https://github.com/pallets/jinja/issues/1068" class="embed-card-link" target="_blank" rel="noopener noreferrer">
    <div class="embed-card-image">
      <img src="https://opengraph.githubassets.com/651df2213bb57abbd2e889d05bdb5648d3f94d3525be472b34a5254d05d3fe64/pallets/jinja/issues/1068" alt="Show some equivalent list comprehensions in filter examples · Issue #1068 · pallets/jinja — I&#39;m willing to write a pull-request for this, but I just want to see what people think before I write it. So the issue is this. I&#39;m very familiar with python. I&#39;m new to Jinja2. Often I find myself..." loading="lazy">
    </div>
    <div class="embed-card-content">
      <div class="embed-card-title">Show some equivalent list comprehensions in filter examples · Issue #1068 · pallets/jinja</div>
      <div class="embed-card-description">I&#39;m willing to write a pull-request for this, but I just want to see what people think before I write it. So the issue is this. I&#39;m very familiar with python. I&#39;m new to Jinja2. Often I find myself...</div>
      <div class="embed-card-meta">GitHub &middot; github.com</div>
    </div>
  </a>
</div>


I often want to reach for non existing list comprehensions in jinja 2, Here are a few nice equivalents.

``` python
a: {{ data | selectattr('x', 'gt', 5) | list }}
b: {{ data | map(attribute='c') | list }} 
c: {{ data | selectattr('x', 'gt', 5) | map(attribute='c') | list }} 
```
