iter (32)
any¶
any(seq: collections.abc.Iterable[typing.Any], attribute: str | None = None) -> bool
Check if at least one of the item in the sequence evaluates to true.
DocStrings
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seq
|
Iterable[Any]
|
An iterable object. |
required |
attribute
|
str | None
|
The attribute name to use on each object of the iterable. |
None
|
Source code in src/jinjarope/iterfilters.py
batch¶
batch(value: Iterable[~V], linecount: int, fill_with: Optional[~V] = None) -> Iterator[List[~V]]
A filter that batches items. It works pretty much like slice
Example
Jinja call:
Result:[['a', 'b'], ['c', 'd'], ['e']]
Example
Jinja call:
Result:[['a', 'b'], ['c', 'x']]
DocStrings
Source code in jinja2/filters.py
batched¶
batched(iterable: collections.abc.Iterable[T], n: int) -> collections.abc.Generator[tuple[T, ...]]
Batch data into tuples of length n. The last batch may be shorter.
Example
Jinja call:
Result:0: 1
2: 3
4: 5
6: 7
8: 9
DocStrings
Examples:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iterable
|
Iterable[T]
|
The iterable to yield as batches |
required |
n
|
int
|
The batch size |
required |
Source code in src/jinjarope/iterfilters.py
chain¶
chain(*iterables: collections.abc.Iterable[T]) -> itertools.chain[T]
Chain all given iterators.
Example
Jinja call:
Result:0
1
2
0
1
2
3
4
DocStrings
Examples:
Source code in src/jinjarope/iterfilters.py
combinations¶
combinations(iterable, r)
Return successive r-length combinations of elements in the iterable.
Example
Jinja call:
Result:('A', 'B')
('A', 'C')
('A', 'D')
('B', 'C')
('B', 'D')
('C', 'D')
DocStrings
combinations_with_replacement¶
combinations_with_replacement(iterable, r)
Return successive r-length combinations of elements in the iterable allowing individual elements to have successive repeats.
Example
Jinja call:
Result:('A', 'A')
('A', 'B')
('A', 'C')
('B', 'B')
('B', 'C')
('C', 'C')
DocStrings
compress¶
compress(data, selectors)
Return data elements corresponding to true selector elements.
Example
Jinja call:
Result:A
C
E
F
DocStrings
first¶
first(environment: 'Environment', seq: 't.Iterable[V]') -> 't.Union[V, Undefined]'
Return the first item of a sequence.
DocStrings
Source code in jinja2/filters.py
flatten_dict¶
flatten_dict(dct: collections.abc.Mapping[str, typing.Any], sep: str = '/', _parent_key: str = '') -> collections.abc.Mapping[str, typing.Any]
Flatten a nested dictionary to a flat one.
DocStrings
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dct
|
Mapping[str, Any]
|
The dictionary to flatten |
required |
sep
|
str
|
The separator to use for joining |
'/'
|
Source code in src/jinjarope/iterfilters.py
groupby¶
groupby(environment: 'Environment', value: 't.Iterable[V]', attribute: Union[str, int], default: Optional[Any] = None, case_sensitive: bool = False) -> 't.List[_GroupTuple]'
Group a sequence of objects by an attribute using Python's
Example
Jinja call:
Result:[('jinja2.utils', [<class 'jinja2.utils.Cycler'>])]
Example
Jinja call:
{{ [{"name": "A", "type": 1}, {"name": "B", "type": 1}, {"name": "C", "type": 2}] | groupby("type") | list }}
[(1, [{'name': 'A', 'type': 1}, {'name': 'B', 'type': 1}]), (2, [{'name': 'C', 'type': 2}])]
DocStrings
Source code in jinja2/filters.py
groupby_first_letter¶
groupby_first_letter(data: collections.abc.Iterable[T], keyfunc: collections.abc.Callable[..., typing.Any] | None = None) -> dict[str, list[T]]
Group given iterable by first letter.
Example
Jinja call:
Result:{'A': ['apple', 'avocado'], 'B': ['banana', 'blueberry'], 'C': ['carrot', 'cherry']}
DocStrings
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Iterable[T]
|
Iterable to group |
required |
keyfunc
|
Callable[..., Any] | None
|
Optional alternative sort function |
None
|
Source code in src/jinjarope/iterfilters.py
groupby_plus¶
groupby_plus(data: collections.abc.Iterable[T], key: collections.abc.Callable[[T], typing.Any] | str | None = None, *, sort_groups: bool = True, natural_sort: bool = False, reverse: bool = False) -> dict[typing.Any, list[T]]
Group given iterable using given group function.
Example
Jinja call:
Result:{'0': ['0'], '20': ['20', '20'], '100': ['100']}
DocStrings
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Iterable[T]
|
Iterable to group |
required |
key
|
Callable[[T], Any] | str | None
|
Sort function or attribute name to use for sorting |
None
|
sort_groups
|
bool
|
Whether to sort the groups |
True
|
natural_sort
|
bool
|
Whether to use a natural sort algorithm |
False
|
reverse
|
bool
|
Whether to reverse the value list |
False
|
Source code in src/jinjarope/iterfilters.py
islice¶
islice(iterable: 'Iterable[T]', *args: 'int | None') -> 'itertools.islice[T]'
Make an iterator that returns selected elements from the iterable.
DocStrings
Examples:
islice('ABCDEFG', 2) --> A B
islice('ABCDEFG', 2, 4) --> C D
islice('ABCDEFG', 2, None) --> C D E F G
islice('ABCDEFG', 0, None, 2) --> A C E G
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iterable
|
Iterable[T]
|
Iterable to slice |
required |
args
|
int | None
|
Arguments passed to itertools.islice |
()
|
Source code in src/jinjarope/iterfilters.py
join¶
join(eval_ctx: 'EvalContext', value: Iterable[Any], d: str = '', attribute: Union[str, int, NoneType] = None) -> str
Return a string which is the concatenation of the strings in the
DocStrings
Source code in jinja2/filters.py
last¶
last(environment: 'Environment', seq: 't.Reversible[V]') -> 't.Union[V, Undefined]'
Return the last item of a sequence.
DocStrings
Source code in jinja2/filters.py
length¶
length(obj, /)
Return the number of items in a container.
Aliases: count
DocStrings
natsort¶
natsort(val: collections.abc.Iterable[T], key: str | collections.abc.Callable[[T], typing.Any] | None = None, reverse: bool = False, ignore_case: bool = True) -> collections.abc.Iterable[T]
Using the natsort package, sort a list naturally.
Required packages: natsort
DocStrings
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
val
|
Iterable[T]
|
the iterable to sort |
required |
key
|
str | Callable[[T], Any] | None
|
If str, sort by attribute with given name. If callable, use it as keygetter. If None, sort by objects itself |
None
|
reverse
|
bool
|
Whether to reverse the sort order |
False
|
ignore_case
|
bool
|
Whether to ignore case for sorting |
True
|
Source code in src/jinjarope/iterfilters.py
pairwise¶
pairwise(items: 'Iterable[T]') -> 'itertools.pairwise[tuple[T, T]]'
Return an iterator of overlapping pairs taken from the input iterator.
Example
Jinja call:
Result:1: 2
2: 3
3: 4
DocStrings
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
Iterable[T]
|
The items to iter pair-wise |
required |
Source code in src/jinjarope/iterfilters.py
permutations¶
permutations(iterable, r=None)
Return successive r-length permutations of elements in the iterable.
Example
Jinja call:
Result:('A', 'B')
('A', 'C')
('A', 'D')
('B', 'A')
('B', 'C')
('B', 'D')
('C', 'A')
('C', 'B')
('C', 'D')
('D', 'A')
('D', 'B')
('D', 'C')
DocStrings
product¶
product(*iterables: 'Iterable[Any]', repeat: 'int' = 1) -> 'itertools.product[tuple[Any, ...]]'
Cartesian product of input iterables.
Example
Jinja call:
Result:('A', 'x')
('A', 'y')
('B', 'x')
('B', 'y')
('C', 'x')
('C', 'y')
('D', 'x')
('D', 'y')
DocStrings
Examples:
product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iterables
|
Iterable[Any]
|
The iterables to create a cartesian product from |
()
|
repeat
|
int
|
The amount of repititions |
1
|
Source code in src/jinjarope/iterfilters.py
reduce_list¶
reduce_list(items: collections.abc.Iterable[T]) -> list[T]
Reduce duplicate items in a list and preserve order.
DocStrings
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
Iterable[T]
|
The iterable to recude to a unique-item list |
required |
reject¶
reject(context: 'Context', value: 't.Iterable[V]', *args: Any, **kwargs: Any) -> 't.Iterator[V]'
Filters a sequence of objects by applying a test to each object,
DocStrings
Source code in jinja2/filters.py
rejectattr¶
rejectattr(context: 'Context', value: 't.Iterable[V]', *args: Any, **kwargs: Any) -> 't.Iterator[V]'
Filters a sequence of objects by applying a test to the specified
DocStrings
Source code in jinja2/filters.py
repeat¶
repeat(obj: T, times: int | None = None) -> collections.abc.Iterable[T]
Make an iterator that returns object over and over again.
DocStrings
Examples:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
T
|
The object to return over and over again |
required |
times
|
int | None
|
The amount of times to return the object (None means infinite) |
None
|
Source code in src/jinjarope/iterfilters.py
reverse¶
reverse(value: Union[str, Iterable[~V]]) -> Union[str, Iterable[~V]]
Reverse the object or return an iterator that iterates over it the other
Example
Jinja call:
Result:<list_reverseiterator object at 0x7507417e21a0>
DocStrings
Source code in jinja2/filters.py
select¶
select(context: 'Context', value: 't.Iterable[V]', *args: Any, **kwargs: Any) -> 't.Iterator[V]'
Filters a sequence of objects by applying a test to each object,
DocStrings
Source code in jinja2/filters.py
selectattr¶
selectattr(context: 'Context', value: 't.Iterable[V]', *args: Any, **kwargs: Any) -> 't.Iterator[V]'
Filters a sequence of objects by applying a test to the specified
DocStrings
Source code in jinja2/filters.py
slice¶
slice(value: Collection[~V], slices: int, fill_with: Optional[~V] = None) -> Iterator[List[~V]]
Slice an iterator and return a list of lists containing
DocStrings
Source code in jinja2/filters.py
sort¶
sort(environment: 'Environment', value: 't.Iterable[V]', reverse: bool = False, case_sensitive: bool = False, attribute: Union[str, int, NoneType] = None) -> 't.List[V]'
Sort an iterable using Python's :func:sorted.
DocStrings
Source code in jinja2/filters.py
unique¶
unique(environment: 'Environment', value: 't.Iterable[V]', case_sensitive: bool = False, attribute: Union[str, int, NoneType] = None) -> 't.Iterator[V]'
Returns a list of unique items from the given iterable.
Example
Jinja call:
Result:<generator object sync_do_unique at 0x750742275be0>
DocStrings
Source code in jinja2/filters.py
zip¶
zip(*items: 'Iterable[T]') -> 'zip[tuple[T, ...]]'
Zip iterables into a single one.
Example
Jinja call:
Result:1: 3
2: 4
DocStrings
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
Iterable[T]
|
The iterables to zip |
()
|
zip_longest¶
zip_longest(*iterables: collections.abc.Iterable[typing.Any], fillvalue: Any = None) -> collections.abc.Iterable[typing.Any]
Make an iterator that aggregates elements from each of the iterables.
Example
Jinja call:
Result:('A', 'x', '-')
('B', 'y', None)
('C', None, None)
('D', None, None)
DocStrings
Examples:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iterables
|
Iterable[Any]
|
The iterables to zip |
()
|
fillvalue
|
Any
|
value to use for filling in case the iterables are of uneven length |
None
|