mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Use 'predicate = bool' as the default predicate for ifilter[false].
This commit is contained in:
parent
f0dfc7ac5c
commit
0c9a318d64
1 changed files with 2 additions and 4 deletions
|
@ -140,8 +140,7 @@ by functions or loops that truncate the stream.
|
|||
\begin{verbatim}
|
||||
def ifilter(predicate, iterable):
|
||||
if predicate is None:
|
||||
def predicate(x):
|
||||
return x
|
||||
predicate = bool
|
||||
for x in iterable:
|
||||
if predicate(x):
|
||||
yield x
|
||||
|
@ -157,8 +156,7 @@ by functions or loops that truncate the stream.
|
|||
\begin{verbatim}
|
||||
def ifilterfalse(predicate, iterable):
|
||||
if predicate is None:
|
||||
def predicate(x):
|
||||
return x
|
||||
predicate = bool
|
||||
for x in iterable:
|
||||
if not predicate(x):
|
||||
yield x
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue