Good use for itertools.dropwhile and itertools.takewhile

Paul Rubin no.email at nospam.invalid
Thu Dec 6 22:29:23 CET 2012


Nick Mellor <thebalancepro at gmail.com> writes:
> I came across itertools.dropwhile only today, then shortly afterwards
> found Raymond Hettinger wondering, in 2007, whether to drop [sic]
> dropwhile and takewhile from the itertools module....
> Almost nobody else of the 18 respondents seemed to be using them.

What?  I'm amazed by that.  I didn't bother reading the old thread, but
I use those functions fairly frequently.  I just used takewhile the
other day, processing a timestamped log file where I wanted to look at
certain clusters of events.  I won't post the actual code here, but
takewhile was a handy way to pull out intervals of interest after an
event was seen.



More information about the Python-list mailing list