Attempt to solve one of the Bloomreach problems in Python