{"action":"opened","issue":{"url":"https://api.github.com/repos/mitsuhiko/jinja2/issues/555","repository_url":"https://api.github.com/repos/mitsuhiko/jinja2","labels_url":"https://api.github.com/repos/mitsuhiko/jinja2/issues/555/labels{/name}","comments_url":"https://api.github.com/repos/mitsuhiko/jinja2/issues/555/comments","events_url":"https://api.github.com/repos/mitsuhiko/jinja2/issues/555/events","html_url":"https://github.com/mitsuhiko/jinja2/issues/555","id":137495170,"number":555,"title":"Problem using loop.index when iterating over itertools.groupby result","user":{"login":"binrush","id":3984423,"avatar_url":"https://avatars.githubusercontent.com/u/3984423?v=3","gravatar_id":"","url":"https://api.github.com/users/binrush","html_url":"https://github.com/binrush","followers_url":"https://api.github.com/users/binrush/followers","following_url":"https://api.github.com/users/binrush/following{/other_user}","gists_url":"https://api.github.com/users/binrush/gists{/gist_id}","starred_url":"https://api.github.com/users/binrush/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/binrush/subscriptions","organizations_url":"https://api.github.com/users/binrush/orgs","repos_url":"https://api.github.com/users/binrush/repos","events_url":"https://api.github.com/users/binrush/events{/privacy}","received_events_url":"https://api.github.com/users/binrush/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-03-01T07:22:59Z","updated_at":"2016-03-01T07:22:59Z","closed_at":null,"body":"Hello. I have strange jinja2 behavior when iterating over result produced by itertoos.groupby function. When I don't use `loop.index`, everything is OK:\r\n\r\n```python\r\nimport operator\r\nimport itertools\r\nfrom jinja2 import Template\r\n\r\nl = [(1, 'a'), (1, 'b'), (2, 'c'), (3, 'd')]\r\ni = itertools.groupby(l, lambda e: operator.getitem(e, 0))\r\ntemplate = \"\"\"\r\n  {% for g in i %}\r\n    {% for e in g[1] %}\r\n      {{ e }}\r\n  {% endfor %}\r\n{% endfor %}\r\n\"\"\"\r\ntpl = Template(template)\r\nprint tpl.render(i=i)\r\n```\r\nOutput is: `(1, 'a')  (1, 'b')   (2, 'c')   (3, 'd')`, so loop iterates over all elements.\r\n\r\nWhen I call loop.index in loop, I have only last element in output:\r\n\r\n```python\r\nimport operator\r\nimport itertools\r\nfrom jinja2 import Template\r\n\r\nl = [(1, 'a'), (1, 'b'), (2, 'c'), (3, 'd')]\r\ni = itertools.groupby(l, lambda e: operator.getitem(e, 0))\r\ntemplate = \"\"\"\r\n  {% for g in i %}\r\n    {% for e in g[1] %}\r\n      {{ e }} {{loop.index}}\r\n  {% endfor %}\r\n{% endfor %}\r\n\"\"\"\r\ntpl = Template(template)\r\nprint tpl.render(i=i)\r\n```\r\nOutput is `(3, 'd') 1`\r\n\r\nIs it a bug or feature?\r\n\r\nP.S. I'm using Jinja2 2.8 and python 2.7"}}