[Python-Dev] itertools predicates

Raymond Hettinger raymond.hettinger at gmail.com
Fri Nov 4 13:29:27 EDT 2016


> On Nov 3, 2016, at 3:51 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> 
> Before there can be a solution, there first has to be a problem that 
> needs solving. "Lack of consistency" is not necessarily a problem. The 
> intertools functions are quite different, they do different things with 
> different APIs. The question here should not be "why don't these 
> functions take None as an argument?", rather it should be "why should 
> these functions take None as an argument?".

I concur with Steven who articulated the issue perfectly.  There isn't an actual problem here that needs to be solved (i.e. not a single user report in 15 years indicating that the API wasn't meeting the needs for real use-cases).  I'm disinclined to churn the API unless there is a real need.

FWIW, groupby() has the predicate as an optional argument so that you can write groupby('aaabbc') and have it group by value (much like the key-function on sorted() is optional).   The two filter variants allow None as the first argument only for historical reasons -- once "bool" came along, it would have been better to write filter(bool, someiterable) in preference to using None which is less clear about its intention.  The takewhile/dropwhile tools didn't have the same constraint to match a historical API, so there was an opportunity to have a clearer API with a simpler signature.

As Terry suggested, if you have other itertools feature requests, please put them on the tracker an assign them to me.

Thank you,


Raymond







More information about the Python-Dev mailing list