Describing itertools.dropwhile(condition, itr)
-
The
dropwhilefunction is used to:- Cycle through each element of an iterable
- Includes elements once any element fails the condition
- Then, every element after that element is returned
- This condition is based on the
conditionparameter - This iterable is based on the
itrparameter dropwhilereturns an iterator that dropsitrelements while ourconditionis satisfied
Illustrating the dropwhile Function
>>> from itertools import dropwhile
>>> cond = lambda x: x>5
>>> nums = [7,6,5,8,4]
>>> itr = dropwhile(cond, nums)
>>> for i in itr: print(i)
5
8
4References
Previous
Next