import sys pairs = ( (2, '2'), (5, '3'), (8, '4'), (11, '5'), (14, '6'), (18, '7'), (21, '8'), (25, '9') ) for line in sys.stdin.readlines(): line = line.strip() ret = [] for c in line: if 'a' <= c <= 'z': for pos, num in pairs: if (ord(c) - ord('a')) <= pos: ret.append(num) break continue ...