Contents
takewhile
dropwhile
span
: Taking and dropping at the same time
Whereas Python’s islice
(and Haskell’s take
and drop
) cut some number of elements from a list, the corresponding takewhile
itertools.takewhile
and dropwhile
inspect the list’s values and truncate the list based on what it contains.
The general concept of taking is to keep some portion of beginning of a series and ignore the remainder.