>>> from itertools import takewhile
>>> nums = [2,4,6,7,9,8]
>>> a = takewhile(lambda x:x%2==0,nums)
>>> print(list(a))
[2, 4, 6]
>>> 8%2
0
>>> from itertools import takewhile
>>> help(takewhile)
Help on class takewhile in module itertools:
class takewhile(builtins.object)
| takewhile(predicate, iterable) --> takewhile object
|
| Return successive entries from an iterable as long as the
| predicate evaluates to true for each entry.
>>> import itertools
>>> print(list(itertools.ifilter(lambda x:x%2==0,[2,4,6,7,9,8])))
[2, 4, 6, 8]
>>> print(list(itertools.ifilterfalse(lambda x:x%2,[2,4,6,7,9,8])))
[2, 4, 6, 8]