---
title: "💭 Show some equivalent list comprehensions in filter examples · ..."
description: "!https://github.com/pallets/jinja/issues/1068"
date: 2023-12-14
published: true
tags:
  - webdev
  - python
  - thought
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 }} 
```

!!! note

    This post is a <a href="/thoughts/" class="wikilink" data-title="Thoughts" data-description="These are generally my thoughts on a web page or some sort of url, except a rare few don&#39;t have a link. These are dual published off of my..." data-date="2024-04-01">thought</a>. It's a short note that I make
    about someone else's content online <a href="/tags/thoughts/" class="hashtag-tag" data-tag="thoughts" data-count=2 data-reading-time=3 data-reading-time-text="3 minutes">#thoughts</a>
