zip¶
Collection Note
This module is part of the ansible.builtin collection. To install the collection, use:
Added in version2.3.
Synopsis¶
- Iterate over several iterables in parallel, producing tuples with an item from each one.
Parameters¶
| Parameter | Defaults / Choices | Comments |
|---|---|---|
| _additional_lists list / elements=any required |
Additional list(s). | |
| _input list / elements=any required |
Original list. | |
| strict bool |
If V(True) return an error on mismatching list length, otherwise shortest list determines output. |
Notes¶
Note
- This is mostly a passthrough to Python's C(zip) function.
Examples¶
# two => [[1, "a"], [2, "b"], [3, "c"], [4, "d"], [5, "e"], [6, "f"]]
two: "{{ [1,2,3,4,5,6] | zip(['a','b','c','d','e','f']) }}"
# three => [ [ 1, "a", "d" ], [ 2, "b", "e" ], [ 3, "c", "f" ] ]
three: "{{ [1,2,3] | zip(['a','b','c'], ['d','e','f']) }}"
# shorter => [[1, "a"], [2, "b"], [3, "c"]]
shorter: "{{ [1,2,3] | zip(['a','b','c','d','e','f']) }}"
# compose dict from lists of keys and values
mydict: "{{ dict(keys_list | zip(values_list)) }}"
Return Values¶
| Key | Data Type | Description | Returned |
|---|---|---|---|
| _value | list | List of lists made of elements matching the positions of the input lists. |