def enumerate_permutations(ensemble):
    """
    énumère les permutations d'un ensemble de façon non récursive

    @param      ensemble        ensemble à permuter
    @return                     itérateur sur les permutations
    """
    if len(ensemble) == 1:
        yield ensemble
    else:
        position = list(range(len(ensemble)))
        while position[0] < len(ensemble):
            memo = []
            for i, p in enumerate(position):
                ensemble[i], ensemble[p] = ensemble[p], ensemble[i]
                memo.append((i, p))
            yield ensemble.copy()
            for i, p in reversed(memo):
                ensemble[i], ensemble[p] = ensemble[p], ensemble[i]
            last = len(position) - 1
            position[last] += 1
            while last > 0 and position[last] >= len(position):
                position[last - 1] += 1
                position[last] = last
                last -= 1
