+ 4
What difference between filter and takewhile function?
2 odpowiedzi
+ 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
+ 6
filter: don't need import.Returns all the elements that satisfy the predicate.
takeWhile: Returns the longest prefix whose elements satisfy the predicate.