Fate of itertools.dropwhile() and itertools.takewhile()

Matt Nordhoff mnordhoff at mattnordhoff.com
Mon Dec 31 01:40:23 EST 2007


Raymond Hettinger wrote:
> I'm considering deprecating these two functions and would like some
> feedback from the community or from people who have a background in
> functional programming.
> 
> * I'm concerned that use cases for the two functions are uncommon and
> can obscure code rather than clarify it.
> 
> * I originally added them to itertools because they were found in
> other functional languages and because it seemed like they would serve
> basic building blocks in combination with other itertools allow
> construction of a variety of powerful, high-speed iterators.  The
> latter may have been a false hope -- to date, I've not seen good
> recipes that depend on either function.
> 
> * If an always true or always false predicate is given, it can be hard
> to break-out of the function once it is running.
> 
> * Both functions seem simple and basic until you try to explain them
> to someone else.  Likewise, when reading code containing dropwhile(),
> I don't think it is self-evident that dropwhile() may have a lengthy
> start-up time.
> 
> * Since itertools are meant to be combined together, the whole module
> becomes easier to use if there are fewer tools to choose from.
> 
> These thoughts reflect my own experience with the itertools module.
> It may be that your experience with them has been different.  Please
> let me know what you think.
> 
> Raymond

FWIW, Google Code Search shows a few users:

<http://www.google.com/codesearch?q=lang%3Apython+%28drop%7Ctake%29while>

Do any of them make good use of them?
-- 



More information about the Python-list mailing list