Cleanup: PEP8 fixes
Avoid `filter` as a variable name

Otherwise it would be redefining the `filter()` function from the standard
library.
Refactored to a more Pythonic style, added docstring