I am creating a script that translates certain characters with directions, and any character that is not one of the known characters is replaced with \"Aaaaah!\".
Use dict and dict.get:
dict
dict.get
my_dict = {'r': 'right', 'l': 'left', 'j': 'jump', 's': 'straight'} # string = input('Terrain: ') string = 'rljsZ' # For test purpose new_string = ''.join(map(lambda x:my_dict.get(x, 'Aaaaah!'), string)) print(new_string)
Output:
'rightleftjumpstraightAaaaah!'