用f弦代替
str
,用
zip_longest
来组合两个弦。
>>> from itertools import zip_longest
>>> int(''.join((x or "") + (y or "") for x, y in zip_longest(f"{a}", f"{b}")))
1425367
如果你有一些 "不进口 "的规则,用内置的zip
来做这件事也不会太难,但你需要对后面的数字进行特殊处理。
>>> int(''.join((x or "") + (y or "") for x, y in zip(f"{a}", f"{b}")) + f"{a}")[len(f"{b}"):] + f"{b}"[len(f"{a}"):]
1425367