using the itertools tool, I have every possible permutation of a given list of numbers, but if the list looks like this:
List=[0,0,0,0,3,6,0,0,5,0,0]
itertools does not “know” that iterating over zeros is wasted work, for example, the following iterations will be displayed in the results:
List=[0,3,0,0,0,6,0,0,5,0,0] List=[0,3,0,0,0,6,0,0,5,0,0]
they are the same, but itertools just takes the first zero (for example) and moves it to fourth place in the list and vice versa.
The question arises: how can I iterate over only some selected numbers and leave others alone, such as zero? It can be with or without itertools .
python list permutation
V. Petretto
source share