Answer to Question #265987 in Python for sai krishna

Question #265987

in the example the first test case number is 9966777819 and this number should be divided into 4 3 3 format

the first divided part should be read a double nine double six. As there are two consecutive 9's,it should be read as double nine.similarly there are two consecutive 6's it should be read as double six

in the second divided part there are three consecutive 7's it should be read as triple seven.

In the third divided part there are no consecutive digits each digit should be read separately.

sample input1

9966777819

sample output1

double nine double six triple seven eight one nine

sample input 2

7299613014

sample output 2

seven two double nine six one three zero one four


1
Expert's answer
2021-11-14T17:02:30-0500
from itertools import groupby

dct = {'1': 'one', '2': 'two', '3': 'three', '4': 'four', '5': 'five', '6': 'six', '7': 'seven', '8': 'eight',
       '9': 'nine', '0': 'zero'}
dct2 = {4: 'quadruple ', 3: 'triple ', 2: 'double '}
tel = input()
groups = [''.join(g) for _, g in groupby(tel[:4])] + [''.join(g) for _, g in groupby(tel[4:7])] + \
         [''.join(g) for _, g in groupby(tel[7:])]
res = ''
for group in groups:
    if len(group) == 1:
        res += ' ' + dct[group[0]]
    else:
        res += ' ' + dct2[len(group)] + dct[group[0]]
print(res.strip())

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS