First I tried using the =
operator to assign a value, but it returned an error, then I tried using string.replace()
:
encrypted_str.replace(encrypted_str[j], dec_str2[k], 2)
and
encrypted_str.replace(encrypted_str[j], unichr(ord(dec_str2[k]) - 32), 2)
But it returns the value of orignal.
Learn how to use the replacement API correctly to give the correct result. There is also some other API that can be used instead of unichr()
.
encrypted_str
is taken from the user encrypted_str = raw_input()
dec_str2
is the freq string entered by the user. The question is hardly related to the variable. I want to know if I am using the replcae()
API replcae()
, since it gives me immutable output for encrypted_str
Can we use encrypted_str[j]
to return a character from a string to define a substring for the replace()
API. I used encrypted_str.replace(encrypted_str[j], unichr(ord(dec_str2[k]) - 32), 1)
max replace 1 instead of 2 (since I only need one replacement).
The actual operation I need to do will be in C as follows: encrypted_str[j] = dec_str2[k] -32
.
Since I'm new to python, I'm trying to find a replacement.
source share