Comment on Building a full-text search engine in 150 lines of Python code (2021)parentComments−chaos_emergent1yHoly shit, I’ve been writing python for 15 years and it’s the first time I’ve seen None used as an identity function. That’s nuts! How does it work under the hood? Does filter have a special case for evaluating None?−echoangle1yYes, that’s just a special case. You can’t call None as a function.https://docs.python.org/3/library/functions.html#filterIf function is None, the identity function is assumed, that is, all elements of iterable that are false are removed.
Comments
Holy shit, I’ve been writing python for 15 years and it’s the first time I’ve seen None used as an identity function. That’s nuts! How does it work under the hood? Does filter have a special case for evaluating None?
Yes, that’s just a special case. You can’t call None as a function.
https://docs.python.org/3/library/functions.html#filter