Actually, I would like to substitute all the chars in a string with its
ascii adding 2, for cracking the naive "Caesar cipher".

So, there is a list of chars to be replaced.

If I use "replace" function, I have to replace them one by one.

Thanks all the same.

On Sun, Feb 24, 2013 at 7:32 PM, Marco Mistroni <[email protected]> wrote:

> You can use replace instead?
>  On 24 Feb 2013 10:59, "Sudo Nohup" <[email protected]> wrote:
>
>>  Dear all,
>>
>> I want to change the value of a char in a string for Python. However, It
>> seems that "=" does not work.
>>
>> Could you help me? Thanks!
>>
>> str = "abcd"
>> result = [char = 'a' for char in str if char == 'c']
>>
>>
>> OR:
>>
>> str = 'abcd'
>> for char in str:
>>     if char == 'a':
>>        char = 'c'
>>
>>
>> OR:
>>
>> str = 'abcd'
>> for i in range(len(str)):
>>     if str[i] == 'a':
>>        str[i] = 'c'
>>
>> (
>> Traceback (most recent call last):
>>   File "<stdin>", line 3, in <module>
>>  TypeError: 'str' object does not support item assignment
>> )
>>
>>
>> James
>>
>>
>>
>>
>>
>> _______________________________________________
>> Tutor maillist  -  [email protected]
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to