The unique filter ignores the case of the strings in the list. For example if I have a list that looks like ["A", "a"] and I apply the unique filter, I will only get "A" in return.
Here is a minimal reproducible example:
from jinja2 import Environment, FileSystemLoader
# Sample data with duplicates
data = {
'items': ["A", "a"]
}
# Create a Jinja2 environment
env = Environment(loader=FileSystemLoader('.'))
# Define the Jinja2 template
template_content = """
Original List:
{{ items }}
Unique Values:
{%- set unique_items = items | unique -%}
{% for item in unique_items %}
- {{ item }}
{% endfor %}
"""
# Load the template from the string
template = env.from_string(template_content)
# Render the template with the data
output = template.render(data)
# Print the output
print(output)
The
unique
filter ignores the case of the strings in the list. For example if I have a list that looks like["A", "a"]
and I apply theunique
filter, I will only get "A" in return.Here is a minimal reproducible example:
I would expect the output to be:
Instead, I get:
Environment: