<commit_before>``reverse``
===========

.. versionadded:: 1.6
    Support for strings has been added in Twig 1.6.

The ``reverse`` filter reverses a sequence, a mapping, or a string:

.. code-block:: jinja

    {% for use in users|reverse %}
        ...
    {% endfor %}

    {{ '1234'|reverse }}

    {# outputs 4321 #}

.. note::

    It also works with objects implementing the `Traversable`_ interface.

.. _`Traversable`: http://php.net/Traversable<commit_msg>added documentation for the preverse_keys argument of the reverse filter (closes #1112)<commit_after>``reverse``
===========

.. versionadded:: 1.6
    Support for strings has been added in Twig 1.6.

The ``reverse`` filter reverses a sequence, a mapping, or a string:

.. code-block:: jinja

    {% for user in users|reverse %}
        ...
    {% endfor %}

    {{ '1234'|reverse }}

    {# outputs 4321 #}

.. tip::

    For sequences and mappings, numeric keys are not preserved. To reverse
    them as well, pass ``true`` as an argument to the ``reverse`` filter:

    .. code-block:: jinja

        {% for key, value in {1: "a", 2: "b"}|reverse %}
            {{ key }}: {{ value }}
        {%- endfor %}

        {# output: 0: c    1: b    2: a #}

        {% for key, value in {1: "a", 2: "b"}|reverse(true) %}
            {{ key }}: {{ value }}
        {%- endfor %}

        {# output: 3: c    2: b    1: a #}

.. note::

    It also works with objects implementing the `Traversable`_ interface.

Arguments
---------

 * ``preserve_keys``: Preserve keys when reversing a mapping or a sequence.

.. _`Traversable`: http://php.net/Traversable
{'fraction_non_alphanumeric': 0.16728624535315986, 'fraction_numerical': 0.023543990086741014, 'mean_word_length': 2.4288747346072186, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '776308', 'n_tokens_mistral': 558, 'n_tokens_neox': 492, 'n_words': 173}