Common Permutation Problem In Python