|
| 1 | +''' |
| 2 | +Problem Statement |
| 3 | +Write python function, sms_encoding() which accepts a sentence and converts it into an abbreviated sentence to be sent as SMS and returns the abbreviated sentence. |
| 4 | + |
| 5 | +Rules are as follows: |
| 6 | +a. Spaces are to be retained as is |
| 7 | +b. Each word should be encoded separately |
| 8 | + |
| 9 | +If a word has only vowels then retain the word as is |
| 10 | + |
| 11 | +If a word has a consonant (at least 1) then retain only those consonants |
| 12 | + |
| 13 | +Note: Assume that the sentence would begin with a word and there will be only a single space between the words. |
| 14 | + |
| 15 | +Sample Input |
| 16 | + |
| 17 | +I love Python |
| 18 | +MSD says I love cricket and tennis too |
| 19 | +I will not repeat mistakes |
| 20 | + |
| 21 | +Expected Output |
| 22 | + |
| 23 | +I lv Pythn |
| 24 | +MSD sys I lv crckt nd tnns t |
| 25 | +I wll nt rpt mstks |
| 26 | +''' |
| 27 | + |
| 28 | +#lex_auth_01269444961482342489 |
| 29 | + |
| 30 | +def sms_encoding(data): |
| 31 | + #start writing your code here |
| 32 | + word=data.split() |
| 33 | + vowels="aeiouAEIOU" |
| 34 | + st="" |
| 35 | + for i in word: |
| 36 | + if(len(i)==1): |
| 37 | + st=st+i |
| 38 | + else: |
| 39 | + for j in i: |
| 40 | + if j not in set(vowels): #consonant |
| 41 | + st=st+j |
| 42 | + st=st+" " |
| 43 | + return st[0:-1] |
| 44 | + |
| 45 | +data="I love Python" |
| 46 | +print(sms_encoding(data)) |
0 commit comments