This paste expires on 2023-04-25 19:03:59.771761. Repaste, or download this paste. . Pasted through v1-api.

import itertools
def char_ranges(s1, s2):
    assert len(s1) == len(s2), "Strings must be the same length"
    ranges = []
    for c1,c2 in zip(s1, s2):
        n1 = ord(c1)
        n2 = ord(c2)
        if n1 > n2:
            n1, n2 = n1, n2
        # n1 is now the 'lower' part of the range
        rng = tuple(chr(n) for n in range(n1, n2 + 1))
        ranges.append(rng)
    return ranges
if __name__ == "__main__":
    s1 = "asdf"
    s2 = "qwer"
    rngs = char_ranges(s1, s2)
    print(f"{rngs=}")
    for chars in itertools.product(*rngs):
        s = "".join(chars)
        print(s)
Filename: seydar.py. Size: 602b. View raw, , hex, or download this file.
15:01 [snoopjedi@denton ~/scratch]
$ python3 seydar.py
rngs=[('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q'), ('s', 't', 'u', 'v', 'w'), ('d', 'e'), ('f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r')]
asdf
asdg
asdh
asdi
asdj
asdk
asdl
asdm
asdn
asdo
asdp
asdq
asdr
asef
aseg
aseh
asei
asej
asek
asel
asem
asen
aseo
asep
aseq
aser
... output truncated to fit on bpaste ...
qwef
qweg
qweh
qwei
qwej
qwek
qwel
qwem
qwen
qweo
qwep
qweq
qwer
Filename: out.txt. Size: 491b. View raw, , hex, or download this file.