Take while

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 takewhileitertools.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.

Sign up for access to the full page, plus the complete archive and all the latest content.