I was going through this solution of pset6 (more comfortable) and I fail to understand the following for loop:

{% for i in range((s2)|length + 1) %}
{% endfor %}

Specifically, I want to know, what is length, from where are we getting it and why does removing it gives an internal server error.


Since it's in a jinja "statment", maybe it's a jinja thing. An internet search for 'jinja length' finds this:


Return the number of items of a sequence or mapping.
Aliases: count

There are a lot of other results you may find interesting.

  • I would like to know why use range((s2)|length + 1) instead of range(s2) – jainilvachhani Jan 10 '19 at 5:10
  • I guess it depends on what s2 is. – DinoCoderSaurus Jan 10 '19 at 12:51
  • s2 is a string. However, using for s in s2 gives an error (TypeError' object has no attribute 'code'). – jainilvachhani Jan 11 '19 at 22:35

Jinja, unfortunately, does not support executing arbitrary Python code, such as


Hence, in order to get the length of a string, the use of a filter is required.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .