5

I know that in Python, map is equivalent to parallel processing class of pool.map from multiprocessing module. Is there a filter equivalent in parallel programming for Python?

2

1 Answer 1

4

Python has most of function orientated programming paradigms that are necessary. Such as map, filter and reduce which you can find here

That being said, multiprocessing doesn't support filter because lambdas are not pickleable by default.
But you can always implement your own using functions mentioned above or reproducing them in manner that suits you using iterators, generators or list comprehension.

One of examples taken from sagemath is:

def pool_filter(pool, func, candidates):
    return [c for c, keep in zip(candidates, pool.map(func, candidates)) if keep]

But it further depends on your implementation.

Sign up to request clarification or add additional context in comments.

1 Comment

There is a typo in your example. p shall be pool

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.