Question 28
Consider the following python code snippet. What will be the rendered output?
from jinja2 import Templatepersons=[ {"Gender":"Male", "Age":40, "Name":"John"}, {"Gender":"Female", "Age":16, "Name":"Samantha"}, {"Gender": "Male", "Age":20, "Name":"Kim"} ]
t="""<ul>{% for group in persons|groupby('Gender') %} <li> {{ group.grouper }} <ul> {% for person in group.list %} <li>{{ person.Name }} is {{ person.Age }} years old</li> {% endfor %} </ul> </li>{% endfor %}</ul>
"""temp=Template(t)print(temp.render(persons=persons))