What difference between filter and takewhile function? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

What difference between filter and takewhile function?

26th Jul 2016, 5:21 AM
Анвар Исмоилов
Анвар Исмоилов - avatar
2 Answers
+ 17
filter will iterate through whole input iterator while takewhile will break once the predicate turn False, if you have an iterator with 1st element that false to predicate, takewhile will break at 1st iteration and return empty
25th Nov 2016, 4:02 PM
skycc
skycc - avatar
+ 6
filter: don't need import.Returns all the elements that satisfy the predicate. takeWhile: Returns the longest prefix whose elements satisfy the predicate.
26th Jul 2016, 5:35 PM
César Augusto Gaete
César Augusto Gaete - avatar