# use of enumerate() in Jinja templates

**URL:** <https://forum.ansible.com/t/use-of-enumerate-in-jinja-templates/22283>\
**Category:** Ansible Project\
**Created:** [August 13, 2016, 6:51am UTC](https://forum.ansible.com/t/use-of-enumerate-in-jinja-templates/22283 "2016-08-13T06:51:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dimon](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@Dimon](https://forum.ansible.com/u/Dimon)\
**Post date:** [August 13, 2016, 6:51am UTC](https://forum.ansible.com/t/use-of-enumerate-in-jinja-templates/22283/1 "2016-08-13T06:51:32Z")

</div>

Hi,  
is there a pattern for implementing loop similar to python:

`  
for (i,name) in enumerate(list\_of\_items):  
print i, name

`

when I try to implement it in Jinja I get error (no enumerate is not available):

`  
{% for (i,name) in enumerate(list\_of\_items) %}  
item{{ i }} = {{ name }}  
{%endfor %}

`

what would be the best way of achieving similar result without implementing my own filter?

---

<div class="post-metadata">

**Author:** ![Dimon](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@Dimon](https://forum.ansible.com/u/Dimon)\
**Post date:** [August 13, 2016, 6:57am UTC](https://forum.ansible.com/t/use-of-enumerate-in-jinja-templates/22283/2 "2016-08-13T06:57:34Z")

</div>

discovered [https://groups.google.com/forum/embed/#!topic/pocoo-libs/gDPqQiRBhdg](https://groups.google.com/forum/embed/#!topic/pocoo-libs/gDPqQiRBhdg) which mentiones loop.index variable. That’ll do for me.
