Python‎ > ‎itertools‎ > ‎

itertools.takewhile()

http://www.adilwaseem.com/

Definition
Return successive entries from an iterable as long as the predicate evaluates to true for each entry.

Syntax
takewhile(predicate, iterable)-> takewhile object

Parameters
function and iterable

Example
The return is:
 from itertools import *
def takewhile1(x):
return x<15

list=[1,3,5,7,9]
for i in takewhile(takewhile1, list ):
print (i)

>>> 
1
3
5
7
9
>>>

Comments