On this page
  1. itertools.dropwhile
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

itertools.dropwhile

Prev: itertools.cycle | Up: itertools | Next: itertools.filterfalse
Rel: itertools.accumulate, itertools.batched, itertools.chain, itertools.combinations
Ref: docs.python.org — itertools.dropwhile
Tags: #public #python3 #stdlib #itertools


Import

import itertools
from itertools import dropwhile

Signature & Overview

itertools.dropwhile(predicate, iterable, /)

Drop items from the iterable while predicate(item) is true.

Usage

from itertools import dropwhile

# Drops leading elements < 5, then yields EVERYTHING afterward
assert list(dropwhile(lambda x: x < 5, [1, 4, 6, 2, 8])) == [6, 2, 8]

Gotchas

REPL Inspect

from itertools import dropwhile
help(dropwhile)

Linked from

Related notes