0
Is there a difference between takewhile and filter?
1 Odpowiedź
+ 3
Did you went through tutorials online ? Anyway there seems to be a big difference ,takewhile function stops checking for element in the array if condition evalutes to false,
For example
from itertools import takewhile
a=[3,4,2,1,6]
print(list(takewhile(lambda x:x>2,a)))
Prints [3,4]
print(list(filter(lambda x:x>2,a)))
Prints [3,4,6]