It looks like takewhile(itertools) is same as filter. Is there any difference? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 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 Réponse
+ 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