It seems very complicated way with focus on output, not the task at hand.
If numbers may contain something else than numerics one should be defensive against it in the first place:
If numbers may contain something else than numerics one should be defensive against it in the first place:
>>> nums = '123-456-789' >>> ''.join(n for n in nums if n.isdigit()) '123456789'However, as there must be calculations performed, it is more convenient to create list of integers:
>>> digits = [int(num) for num in nums if num.isdigit()] >>> digits [1, 2, 3, 4, 5, 6, 7, 8, 9]We can return True or False on condition without if-conditional:
>>> digits[0] == 4 False >>> digit[3] + 1 >= digit[5] FalseWe can put all these rules into list and use enumerate() to indicate which rules passed which not. Or use itertools.groupby() if we need present result consecutively.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.