On Wed, Mar 7, 2018 at 2:33 AM, Kirill Balunov <kirillbalu...@gmail.com> wrote: > > > 2018-03-06 17:55 GMT+03:00 Chris Angelico <ros...@gmail.com>: >> >> If the first argument is None, the identity function is assumed. That >> is, all elements of the iterable that are false are removed; it is >> equivalent to (item for item in iterable if item). It is approximately >> equivalent to (but faster than) filter(bool, iterable). >> >> ChrisA >> -- >> https://mail.python.org/mailman/listinfo/python-list > > > If you look in C source for `filter_next` > https://github.com/python/cpython/blob/5d92647102fac9e116b98ab8bbc632eeed501c34/Python/bltinmodule.c#L593, > there is a line: > > int checktrue = lz->func == Py_None || lz->func == (PyObject *)&PyBool_Type; > > So the only difference between `filter(None, ls`) and `filter(bool, ls)` is > LOAD_NAME vs LOAD_CONST and that `None` is checked before than `bool`. >
Assuming that nobody's shadowed the name 'bool' anywhere, which has to be checked for at run time. (Which is the job of LOAD_NAME.) ChrisA -- https://mail.python.org/mailman/listinfo/python-list