Python Language Create A Function From A Relation