zip_longest¶
Collection Note
This module is part of the ansible.builtin collection. To install the collection, use:
Added in version2.3.
Synopsis¶
- Make an iterator that aggregates elements from each of the iterables. If the iterables are of uneven length, missing values are filled-in with O(fillvalue). Iteration continues until the longest iterable is exhausted.
Parameters¶
| Parameter | Defaults / Choices | Comments |
|---|---|---|
| _additional_lists list / elements=any required |
Additional list(s). | |
| _input list / elements=any required |
Original list. | |
| fillvalue any |
Filler value to add to output when one of the lists does not contain enough elements to match the others. |
Notes¶
Note
- This is mostly a passthrough to Python's C(itertools.zip_longest) function
Examples¶
# X_fill => [[1, "a", 21], [2, "b", 22], [3, "c", 23], ["X", "d", "X"], ["X", "e", "X"], ["X", "f", "X"]]
X_fill: "{{ [1,2,3] | zip_longest(['a','b','c','d','e','f'], [21, 22, 23], fillvalue='X') }}"
Return Values¶
| Key | Data Type | Description | Returned |
|---|---|---|---|
| _value | list | List of lists made of elements matching the positions of the input lists. |