# option 1: string slices
def get_slices_str(n, sizes, n_digits=11):
s = f'{n:0{n_digits}}'
prev = 0
for size in sizes:
yield s[prev : prev + size]
prev += size
# option 2: math
def get_slices_int(n, sizes, n_digits=11):
for size in sizes:
n_digits -= size
val, n = divmod(n, 10 ** n_digits)
yield f'{val:0{size}}'
from timeit import timeit
from random import sample
# generate a sample with 1000 random numbers between 0 and 999999
numbers = sample(range(1000000), 1000)
# execute each test 300 times
params = { 'number' : 300, 'globals': globals() }
sizes = [2, 2, 1, 3, 3]
# execution times are in seconds
print(timeit('for n in numbers:\n " ".join(get_slices_str(n, sizes))', **params))
print(timeit('for n in numbers:\n " ".join(get_slices_int(n, sizes))', **params))
IyBvcHRpb24gMTogc3RyaW5nIHNsaWNlcwpkZWYgZ2V0X3NsaWNlc19zdHIobiwgc2l6ZXMsIG5fZGlnaXRzPTExKToKICAgIHMgPSBmJ3tuOjB7bl9kaWdpdHN9fScKICAgIHByZXYgPSAwCiAgICBmb3Igc2l6ZSBpbiBzaXplczoKICAgICAgICB5aWVsZCBzW3ByZXYgOiBwcmV2ICsgc2l6ZV0KICAgICAgICBwcmV2ICs9IHNpemUKCiMgb3B0aW9uIDI6IG1hdGgKZGVmIGdldF9zbGljZXNfaW50KG4sIHNpemVzLCBuX2RpZ2l0cz0xMSk6CiAgICBmb3Igc2l6ZSBpbiBzaXplczoKICAgICAgICBuX2RpZ2l0cyAtPSBzaXplCiAgICAgICAgdmFsLCBuID0gZGl2bW9kKG4sIDEwICoqIG5fZGlnaXRzKQogICAgICAgIHlpZWxkIGYne3ZhbDowe3NpemV9fScKCmZyb20gdGltZWl0IGltcG9ydCB0aW1laXQKZnJvbSByYW5kb20gaW1wb3J0IHNhbXBsZQoKIyBnZW5lcmF0ZSBhIHNhbXBsZSB3aXRoIDEwMDAgcmFuZG9tIG51bWJlcnMgYmV0d2VlbiAwIGFuZCA5OTk5OTkKbnVtYmVycyA9IHNhbXBsZShyYW5nZSgxMDAwMDAwKSwgMTAwMCkKIyB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