Skip to content

Slice returns one extra item when slice count is a divisor of iterable length and fill_with not none #2118

@matiasilva

Description

@matiasilva

The slice filter returns one extra item when the slice count can divide the iterable length completely and a fill_with value is used.

Example:

{% set a = [1, 2, 3, 4] %}
{{ a|slice(4, 'foo')|list }}

Output:

[[1, 'foo'], [2, 'foo'], [3, 'foo'], [4, 'foo']]

Expected output:

[[1], [2], [3], [4]]

Environment:

  • Python version: 3.10.12
  • Jinja version: 3.1.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions