- 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
7 odpowiedzi
+ 2
Shahir,
I wrote a bit of explanation in the code. Hope it helps.
+ 2
Very helpful thanks
+ 1
Something like this?
https://code.sololearn.com/ckjZHa8GAboM/?ref=app
+ 1
Could you please explain me that code?
+ 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
0
Because what you have correctly replace in one step, will be replaced again in another step.
0
Then what do you suggest me??