I need to replace parts of a string with what it matches in a dictionary. I have restrictions and to change strings only functions i can use are .strip, .split, .append, .join, .format. I cant use replace.
I return gfloflgolgf
def sub(my_dict, phrase): for keys, values in my_dict.items(): s = phrase.split(keys) phrase = values.join(s) return phrase my_dict = { 'c':'.', 'p':'f', 'a':'g', 'l':'e', 'e':'l', ' ':'o' } phrase = "ape pea lap"should return gfloflgoegf
I return gfloflgolgf