Permutations with repetition without two consecutive equal elements
问题 I need a function that generates all the permutation with repetition of an iterable with the clause that two consecutive elements must be different; for example f([0,1],3).sort()==[(0,1,0),(1,0,1)] #or f([0,1],3).sort()==[[0,1,0],[1,0,1]] #I don't need the elements in the list to be sorted. #the elements of the return can be tuples or lists, it doesn't change anything Unfortunatly itertools.permutation doesn't work for what I need (each element in the iterable is present once or no times in