Given an array of numbers (in string format), you must return a string. The numbers correspond to the letters of the alphabet in reverse order: a=26, z=1 etc. You should also account for `'!'`, `'?'` and `' '` that are represented by '27', '28' and '29' respectively.

All inputs will be valid.

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Data structures

Starter code: def switcher(arr):
	

Solutions:
def switcher(arr):
	d = {str(i): chr(123 - i) for i in range(1, 27)}
	d.update({'27': '!'})
	d.update({'28': '?'})
	d.update({'29': ' '})
	d.update({'0': ''})
	return ''.join([d[str(i)] for i in arr])


import string
letters = string.ascii_lowercase[::-1] + '!? '

def switcher(arr):
	return ''.join([letters[ch - 1] for ch in map(int, arr) if ch])


chars = '_zyxwvutsrqponmlkjihgfedcba!? '

def switcher(arr):
	return ''.join((chars[int(i)] for i in arr if i != '0'))


from string import ascii_lowercase as abc
ch = abc[::-1] + '!? '

def switcher(arr):
	return ''.join((ch[int(x) - 1] if x != '0' else '' for x in arr))


def switcher(arr):
	trans = {'26': 'a', '25': 'b', '24': 'c', '23': 'd', '22': 'e', '21': 'f', '20': 'g', '19': 'h', '18': 'i', '17': 'j', '16': 'k', '15': 'l', '14': 'm', '13': 'n', '12': 'o', '11': 'p', '10': 'q', '9': 'r', '8': 's', '7': 't', '6': 'u', '5': 'v', '4': 'w', '3': 'x', '2': 'y', '1': 'z', '27': '!', '28': '?', '29': ' '}
	return ''.join((trans[a] for a in arr if a in trans))


STR = '+zyxwvutsrqponmlkjihgfedcba!? '

def switcher(arr):
	return ''.join((STR[int(x)] for x in arr)).replace('+', '')


def switcher(arr):
	return ''.join(({'27': '!', '28': '?', '29': ' '}.get(e, chr(abs(int(e) - 26) + 97)) for e in arr))


alphabet = ['z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'm', 'l', 'k', 'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a', '!', '?', ' ']

def switcher(arr):
	return ''.join([alphabet[int(i) - 1] for i in arr])


def switcher(arr):
	return ''.join((chr(123 - int(i)) for i in arr)).translate(str.maketrans('`_^', '!? '))


def switcher(arr):
	return ''.join(({'27': '!', '28': '?', '29': ' '}.get(i, chr(123 - int(i))) for i in arr))