Here is my code and error message, and wondering in Python, if I want to assign the value of one character to the value of another character in a string, how to do it?
Error message:
str[i] = str[i+1]
TypeError: 'str' object does not support item assignment
Source code:
class Solution(object):
def RemoveDupCharacters(self, str):
dic = {}
for i in range(0,255):
dic[i] = 0
for i in range(len(str)):
if dic[ord(str[i])] == 0:
dic[ord(str[i])] = 1
str[i] = str[i+1]
return str
if __name__ == "__main__":
s = Solution()
print s.RemoveDupCharacters('aaaa')