class Solution(object):
def getPositions(self, s):
mapping = {}
for i in range(len(s)):
if s[i] not in mapping:
mapping[s[i]] = [i]
elif s[i] in mapping:
mapping[s[i]].append(i)
return mapping.values()
I would expect
getPositions("paper") == getPositions("title")
to be true but the output actually ends up being:
[[1], [0, 2], [4], [3]] == [[1], [4], [0, 2], [3]]
Shouldn't the values of the character in the strings not matter in this method and what is causing the change in expected output?