I initially tried using =
operator to assign 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 is returning the orignal value.
Help out as to how to use the replace API properly to give the correct result
Also is there any other API that can be used instead of unichr()
.
The encrypted_str
is being taken from the user by encrypted_str = raw_input()
dec_str2
is the freq string being input by user.
The issue hardly concerns the variable
I want to know if I am using the replcae()
API incorrectly as it is giving me unchanged output for encrypted_str
Can we use encrypted_str[j]
would return a character from the string to define the sub string 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 (as I need just the one replacement).
The actual operation that I need to be done will be in C as follows:
encrypted_str[j] = dec_str2[k] -32
.
As I am new to python I am trying to find a substitute.