Python Constraint Satisfaction Problem