-
-
Notifications
You must be signed in to change notification settings - Fork 32k
Predicates in itertools and filter #102105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You can patch
RemarkFormally speaking, a predicate must return True or False (in the sense of the language). We abusively call a function a predicate if it returns something which can be implicitly interpreted as a boolean value. I think this is not limited to this specific part of the documentation and there should probably be other locations where we write "true" instead of |
I concur that the "is False" (uppercase) in the For Please make a PR and assign to me for review. Thanks for finding these. It's interesting that no one noticed in the 12 years they have been published. |
…102189) (cherry picked from commit 81bf10e) Co-authored-by: Stefan Pochmann <[email protected]>
(cherry picked from commit 81bf10e) Co-authored-by: Stefan Pochmann <[email protected]>
Documentation
filterfalse
The doc says "Make an iterator that filters elements from iterable returning only those for which the predicate is
False
". That's not correct, it also returns other false elements:quantify
This recipe has the opposite issue:
It says "true", but it only really works with
True
. Other predicates, likere.compile(...).match
returningre.Match
objects orNone
, don't work andquantify
crashes. Predicates returning numbers other than 1 and 0 don't crash it but lead to wrong "counts". Soquantify
is limited. A pity and an odd outlier, since the other six tools/recipes andfilter
all support Python's general truth value concept.The easy fix is to map
bool
over the predicate values:I don't see something "nicer" with the available tools/recipes. If only there was a
length
recipe, then we could do:filter
The doc says:
The "returns true" doesn't work well. I'd say "returns a true value" or "for which function is true".
The last paragraph has the same issue:
Linked PRs
The text was updated successfully, but these errors were encountered: