itertools.product()
This is a task made for itertools.product(). As the docs say, product(A, B, C) is equivalent to ((a,b,c) for a in A for b in B for c in C). The c cycles the fastest, then 'b' and a is the slowest. Like an odometer.
The trick is how to set up the iterables A, B, CAs @AustinHastings pointed out, etc. to get the pattern you wantitertools. In the codeproduct solution below, pattern is the set of wheels in the odometer. If a doesn't work right unless you start value is provided, the wheels are rotated so the first position in the wheel matchesat the startbeginning. So here's an alternate solution:
import itertools as it
DIGIT = '0123456789'
LETTER = 'ACDEFGHJKMNPQRTUVWXYZ'
DIGLET = DIGIT + LETTER
def mbi_gen(start=None):
pattern = [DIGIT[1:], # leading non-zero digit
LETTER,
DIGLET,
DIGIT,
LETTER,
DIGLET,
DIGIT,
LETTER,
LETTER,
DIGIT,
DIGIT
]
if start:
forindices pos,= [pattern[i].index(char, seqc) for i,c in enumerate(zip(start,)]
else:
indices = [0]*len(pattern)):
while True:
print yield ''.join(f"{pos},pat[i] {char},for {seq}"pat,i end="in ->zip(pattern, "indices))
index = seq.index for i in range(charlen(indices)
-1, -1, -1):
pattern[pos] = seq[index:]indices[i] ++= seq[:index]1
printif indices[i] < len(f"{char}pattern[i]):
{pattern[pos]}") break
yield from (''.join(seq) for seq in it.product(*pattern)) indices[i] = 0
MBIs = list(it.islice(mbi_gen('3C12D34EF56'), 10000)
itertools.product()
This is a task made for itertools.product(). As the docs say, product(A, B, C) is equivalent to ((a,b,c) for a in A for b in B for c in C). The c cycles the fastest, then 'b' and a is the slowest. Like an odometer.
import itertools as it
DIGIT = '0123456789'
LETTER = 'ACDEFGHJKMNPQRTUVWXYZ'
DIGLET = DIGIT + LETTER
def mbi_gen(start=None):
pattern = [DIGIT[1:], # leading non-zero digit
LETTER,
DIGLET,
DIGIT,
LETTER,
DIGLET,
DIGIT,
LETTER,
LETTER,
DIGIT,
DIGIT
]
yield from (''.join(seq) for seq in it.product(*pattern))