yield colors[i]
colors[i], colors[-1] = colors[-1], colors[i]
current_run = current_run + 1 if i == n - 1 else 1
if __name__ == '__main__':
    colors = ['red', 'blue', 'green', 'yellow']
for color in choose(colors, 100, maxrun=4):
    pass
Sorting algorithm to keep equal values separated