This is a little weird because of the use of zip() to turn the list of 
integers into a list of lists, but still fairly readable IMO:

foo | zip | map('sum', start=-1)

On Friday, January 21, 2022 at 8:14:27 AM UTC-5 [email protected] wrote:

> Hi
> I have this list of ints:
>
> selection:
>   - 1
>   - 4
>   - 5
>   - 7
>
> I'd like to subtract 1 from each item, so that I will end up with:
>
> selection:
>   - 0
>   - 3
>   - 4
>   - 6
>
> I'd like to avoid adding an intermediary set_fact loop to do the math.
> If I define this filter:
>
> def subtract(number, amount=1):
>     return number - amount
>
> Then I can accomplish what I want using:
>
> selection|map('subtract')
>
> which is reasonably clean and understandable.
>
> But before I add a new filter - is there any other way to achieve this?
>
>
> thx
>
>
> -- 
> Dick Visser
> Trust & Identity Service Operations Manager
> GÉANT
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/e8ddd0eb-3ab3-41ee-be68-0bbe7db48b10n%40googlegroups.com.

Reply via email to