Generate all permutations of a list without adjacent equal elements
This is along the lines of Thijser’s currently incomplete pseudocode. The idea is to take the most frequent of the remaining item types unless it was just taken. (See also Coady’s implementation of this algorithm.) import collections import heapq class Sentinel: pass def david_eisenstat(lst): counts = collections.Counter(lst) heap = [(-count, key) for key, count in … Read more