It looks like takewhile(itertools) is same as filter. Is there any difference? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

It looks like takewhile(itertools) is same as filter. Is there any difference?

I have tested and it looks like they are inter changeable.

29th Oct 2017, 2:04 PM
John S.R. LEE
John S.R. LEE - avatar
1 Answer
+ 1
I believe takewhile iterates only till it finds the first mismatch/false predicate and then stops. however filter completes full iteration over the predicate range irrespective of intermediate mismatch/false.
29th Oct 2017, 5:35 PM
Anil
Anil - avatar