Post 9wEfFc1C3JhpBruCDw by gordon@gluten.space
(DIR) More posts by gordon@gluten.space
(DIR) Post #9wEdfdPbIGZR8LbPLU by borderdoggo@social.mochi.academy
2020-06-19T08:24:52Z
0 likes, 1 repeats
Is anyone know how to use filters to "reduce" a list but to keep only the items that are not present in an other list?I want to do it using filters only (no loop)
(DIR) Post #9wEeczBJzvjxjjDy08 by borderdoggo@social.mochi.academy
2020-06-19T08:35:34Z
0 likes, 1 repeats
it seems I can test something like:"{{ mylist | reject('match', myotherlist) }}"
(DIR) Post #9wEescEh4pCVCnFqHw by gordon@gluten.space
2020-06-19T08:36:10.588857Z
0 likes, 0 repeats
@borderdoggo can you implement new filters? Because python sets are perfect for that:s1 = {1, 2, 3}s2 = {2, 3, 4}print(s1 - s2) # only elements in s1 that aren’t present in s2print(s2 - s1) # only element in s2 that aren’t present in s1print(s1 ^ s1) # only elements that are unique to each set (exclude common values)
(DIR) Post #9wEesdSuVSAP1Aui5Q by borderdoggo@social.mochi.academy
2020-06-19T08:38:21Z
0 likes, 1 repeats
@gordon I could implement new filters but I’m working on a touchy project at work and the aim is keeping it simple and straight forward.I’m afraid that defining new filters will get my PR rejected…
(DIR) Post #9wEfFc1C3JhpBruCDw by gordon@gluten.space
2020-06-19T08:40:37.907601Z
0 likes, 0 repeats
@borderdoggo i understand. In fact, i just saw that those operators are present as the ansible filters difference and symmetric_difference, would it work for you?
(DIR) Post #9wEfFcGn7KBNyFCeXI by borderdoggo@social.mochi.academy
2020-06-19T08:42:33Z
0 likes, 1 repeats
@gordon aaaaah yes, purrfect !I wonder why I didn’t stumbled across this in my search, because I found lists of filtes to work on lists and map but not this ones…Thank you!
(DIR) Post #9wEh6XRRtlG4IZzGqW by borderdoggo@social.mochi.academy
2020-06-19T09:03:20Z
0 likes, 1 repeats
I was pointed to the right filter witch is difference by @gordon (which is pretty obvious but I couldn’t find it… we could have a better indexed documentation in ansible)
(DIR) Post #9wEjBI0Avlnhljci9Y by gordon@gluten.space
2020-06-19T09:23:20.608161Z
0 likes, 0 repeats
@borderdoggo yeah finding things in the documentation is always a pain T_T and the search engine is crap
(DIR) Post #9wEjBIIxnupUi0PiRE by borderdoggo@social.mochi.academy
2020-06-19T09:26:34Z
0 likes, 1 repeats
@gordon I always end up struggling with filters that are not correctly indexed or not well explained…