Python implementation of permutations based on lists.