Adding a Filter function similar to the one in python