Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def freqAlphabets(s: str) -> str:
- # Define a dictionary to map digits to their corresponding ASCII characters
- ascii_dict = {
- '1': 'a',
- '2': 'b',
- '3': 'c',
- '4': 'd',
- '5': 'e',
- '6': 'f',
- '7': 'g',
- '8': 'h',
- '9': 'i',
- '10#': 'j',
- '11#': 'k',
- '12#': 'l',
- '13': 'm',
- '14': 'n',
- '15': 'o',
- '16': 'p',
- '17': 'q',
- '18': 'r',
- '19': 's',
- '20': 't',
- '21': 'u',
- '22': 'v',
- '23': 'w',
- '24': 'x',
- '25': 'y',
- '26': 'z'
- }
- # Split the input string into separate digits
- digits = []
- i = 0
- while i < len(s):
- if i+2 < len(s) and s[i+2] == '#':
- digits.append(s[i:i+3])
- i += 3
- else:
- digits.append(s[i])
- i += 1
- # Convert each digit to its corresponding ASCII character using the dictionary
- result = ''
- for digit in digits:
- if digit in ascii_dict:
- result += ascii_dict[digit]
- else:
- result += ascii_dict[digit[0]]
- if digit[1] != '0':
- result += ascii_dict[digit[1]]
- return result
- def main():
- print(freqAlphabets("22#10#21"))
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement