Yes, you can
from functools import partial
clean = partial(filter, None)
def _apply(mols, fn, *args, **kwargs):
f = partial(fn, *args, **kwargs)
return map(f, clean(mols))
def foo(m, a, b, c=123):
return [m, a, b, c]
print _apply([11,22,'',33], foo, 'aa', 'bb', c=475)
(in python2, consider itertools.imap/ifilter
instead of map/filter
to avoid temporary lists).
The above illustrates "partial application", even more elegant would be currying, i.e. a function that returns a partially applied version of itself when called with less arguments than expected. Python doesn't have currying built-in, but it's easy to implement as a decorator (see https://stackoverflow.com/a/9458386/989121):
@curry
def join_three(a,b,c):
return '%s-%s-%s' % (a,b,c)
mols = [11,22,33]
print map(join_three('aa', 'bb'), mols)
# prints ['aa-bb-11', 'aa-bb-22', 'aa-bb-33']
That said, functional style is frowned upon in python, in most cases, comprehensions and generators are more "pythonic".