I'm trying to create a function that iterates through a string, finds characters that match to keys in a dictionary and replaces that character with the value in the dictionary for that key. However it currently only replaces first occurrence of a letter that is in the dictionary and stops there, where am I going wrong?
d = {
'I':'1', 'R':'2', 'E':'3', 'A':'4', 'S':'5', 'G':'6', 'T':'7', 'B':'8', 'O':'0',
'l':'1', 'z':'2', 'e':'3', 'a':'4', 's':'5', 'b':'6', 't':'7', 'g':'9', 'o':'0',
}
def cypher(string):
for i in string:
if i in d:
a = string.replace(i,d[i])
return a