Skip to content

Implement 'batch' filter #136

@flexferrum

Description

@flexferrum

Implement 'batch' filter according to the jinja2 specification:

https://jinja.palletsprojects.com/en/2.10.x/templates/#batch

A filter that batches items. It works pretty much like slice just the other way round. It returns a list of lists with the given number of items. If you provide a second parameter this is used to fill up missing items.

For instance, batch(3, 0) applied to the list [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] should give the list of three lists:

[[1, 2, 3, 4, 5, 6],
 [7, 8, 9, 10, 11, 0],
 [12, 13, 14, 15, 16, 0]]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions