Solved by ptrblck in post #2 
              
              
                I guess you could use itertools.permutations to permute your list. 
PS: this doesn’t seem to be PyTorch-specific, so note that you might get a faster and better answer e.g. on StackOverflow.