Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import string
- line = "3833###108##333 - 3333"
- def isvalid(symb):
- return (symb >= '0' and symb <= '9') or (symb=='#')
- def isdigit(symb):
- return (symb >= '0' and symb <= '9')
- def double_last_digit(arr):
- if len(arr) > 0:
- return arr[len(arr)-1]
- def check(line):
- prev = 'a'
- symb = 0
- arr = []
- length = len(line)
- skip=False
- sharp_skip = False
- j = 0
- for i in range(0, len(line)):
- symb = line[i]
- if not isvalid(line[i]):
- continue
- if symb == prev and (skip == True or sharp_skip == True):
- continue
- else:
- skip = False
- sharp_skip = False
- if symb == prev and sharp_skip == False and isdigit(symb):
- arr.append(symb)
- skip = True
- if symb == prev == '#' and sharp_skip == False:
- double_last_digit(arr)
- sharp_skip=True
- prev = symb
- print(''.join(arr))
- check(line)
- '''if len(sys.argv) > 1:
- check(sys.argv[1])'''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement