Advertisement
avv210

Untitled

Mar 22nd, 2023
892
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1. def freqAlphabets(s: str) -> str:
  2.     # Define a dictionary to map digits to their corresponding ASCII characters
  3.     ascii_dict = {
  4.         '1': 'a',
  5.         '2': 'b',
  6.         '3': 'c',
  7.         '4': 'd',
  8.         '5': 'e',
  9.         '6': 'f',
  10.         '7': 'g',
  11.         '8': 'h',
  12.         '9': 'i',
  13.         '10#': 'j',
  14.         '11#': 'k',
  15.         '12#': 'l',
  16.         '13': 'm',
  17.         '14': 'n',
  18.         '15': 'o',
  19.         '16': 'p',
  20.         '17': 'q',
  21.         '18': 'r',
  22.         '19': 's',
  23.         '20': 't',
  24.         '21': 'u',
  25.         '22': 'v',
  26.         '23': 'w',
  27.         '24': 'x',
  28.         '25': 'y',
  29.         '26': 'z'
  30.     }
  31.  
  32.     # Split the input string into separate digits
  33.     digits = []
  34.     i = 0
  35.     while i < len(s):
  36.         if i+2 < len(s) and s[i+2] == '#':
  37.             digits.append(s[i:i+3])
  38.             i += 3
  39.         else:
  40.             digits.append(s[i])
  41.             i += 1
  42.  
  43.     # Convert each digit to its corresponding ASCII character using the dictionary
  44.     result = ''
  45.     for digit in digits:
  46.         if digit in ascii_dict:
  47.             result += ascii_dict[digit]
  48.         else:
  49.             result += ascii_dict[digit[0]]
  50.             if digit[1] != '0':
  51.                 result += ascii_dict[digit[1]]
  52.  
  53.     return result
  54.  
  55. def main():
  56.     print(freqAlphabets("22#10#21"))
  57.  
  58. if __name__ == "__main__":
  59.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement