fork(1) download
  1. rem_s = lambda x: list(filter(str.isdigit, x))
  2. two_d = lambda x: x if len(x[-1]) > 1 else x[:-2] + [x[-2][:2]] + [[x[-2][-1], x[-1][-1]]]
  3. raw_p = lambda x: '-'.join(map(''.join, two_d([x[i:i+3] for i in range(0, len(x), 3)])))
  4. phone = lambda x: raw_p(rem_s(x)) if len(rem_s(x)) > 3 else ''.join(rem_s(x))
  5. while True:
  6. inp = str(raw_input())
  7. if inp == '':
  8. break
  9. else:
  10. print(phone(inp))
Success #stdin #stdout 0.04s 44680KB
stdin
1
12
123
1234
12345
123TOP45KEK6
1234567
12-34-56-78
123456789FUCK YOU
9 - 33 2176--856



stdout
1
12
123
12-34
123-45
123-456
123-45-67
123-456-78
123-456-789
933-217-68-56