pull_all_by()
Removes all elements from array that have the same value as the result of calling the iteratee on each element of values. The iteratee is invoked with one argument: (value).
Implementation
Args: array: The array to modify. values: The values to remove. iteratee: The iteratee to transform values. Returns: A new list with the specified values removed.
Example
pull_all_by([1, 2, 3], [2, 3], lambda x: x % 2)
Expected output: [1]
Source Code
def pull_all_by(
array: List[T], values: List[T], iteratee: Optional[Callable[[T], Any]] = None
) -> List[T]:
if iteratee is None:
return [x for x in array if x not in values]
keys = {iteratee(v) for v in values}
return [x for x in array if iteratee(x) not in keys]