- 3

Why doesn't it not working properly???

b = {'9':'0','8':'1','7':'2','6':'3','5':'4','4':'5','3':'6','2':'7','1':'8','0':'9'} y = input() for key, value in b.items(): y = y.replace(key, value) print(y) I have to replace the elements the with corresponding elements in a dictionary

3rd Aug 2021, 4:07 PM
Shahir
Shahir - avatar
7 odpowiedzi
+ 2
Shahir, I wrote a bit of explanation in the code. Hope it helps.
5th Aug 2021, 8:00 AM
Ipang
+ 2
Very helpful thanks
5th Aug 2021, 8:02 AM
Shahir
Shahir - avatar
4th Aug 2021, 5:04 AM
Ipang
+ 1
Could you please explain me that code?
4th Aug 2021, 7:11 AM
Shahir
Shahir - avatar
+ 1
Shahir How about this one? :- b = {ord(x):ord(y) for x, y in b.items()} print(input().translate(b)) Or this one? :- print("".join(b.get(x, x) for x in input())) # Hope this helps
5th Aug 2021, 2:54 PM
Calvin Thomas
Calvin Thomas - avatar
0
Because what you have correctly replace in one step, will be replaced again in another step.
3rd Aug 2021, 4:12 PM
Ipang
0
Then what do you suggest me??
4th Aug 2021, 2:03 AM
Shahir
Shahir - avatar