Solved PERM problem (Python)