It looks like takewhile(itertools) is same as filter. Is there any difference? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 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 Antwort
+ 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