For a single line solution:
In [30]: from itertools import dropwhile In [31]: list(reversed(tuple(dropwhile(lambda x: x is None, reversed([1, 2, 3, None, 4, None, None]))))) Out[31]: [1, 2, 3, None, 4]
If you want to reuse it, here is a point-free definition:
In [36]: from functional import compose, partial In [37]: varargs = lambda *args: args In [38]: compose_mult = compose(partial(reduce, compose),varargs)
Marcin
source share