I have seen a pattern repeated a couple times in my team's code, it looks like this
numbers = [1, 2, 3, 4]
even_numbers = [n for n in numbers if n % 2 == 0]
odd_numbers = [n for n in numbers if n % 2 != 0]
I was wondering if there is a function somewhere (I have looked around but haven't been able to find it) that would do something like this
numbers = [1, 2, 3, 4]
even_numbers, odd_numbers = fork(numbers, lambda x: x % 2 == 0)
So, this function I am looking for, would receive an iterable and a function, and return two lists, one would be the values that match a provided condition, and the other would be the ones that didn't.
Is there something around python's standard library that achieves this?