#Skip to menu

Lexicographic permutations

First read the problem description.
def next_permutation(a):
    i = len(a) - 1
    while a[i-1] >= a[i]:
        i -= 1

    j = len(a)
    while a[j-1] <= a[i-1]:
        j -= 1

    a[i-1], a[j-1] = a[j-1], a[i-1]

    i += 1
    j = len(a)
    while i < j:
        a[i-1], a[j-1] = a[j-1], a[i-1]
        i += 1
        j -= 1


digits = list(range(0, 9+1))
for _ in range(1_000_000-1):
    next_permutation(digits)

Source code of the solution(s):