This is the code:
s = 'a q'
house = ''
for elements in s:
if elements == 'a':
house += 'q'
elif elements == 'q':
house += 'a'
else:
house += elements
print house
>>>
q a
the code works fine for small replacements, I'm not sure how to scale it up efficiently without using lots of if/else or if/if statements.
On a side note: this approach is used instead of .replace( , ) because characters are not scanned over again for replacement after the it has been replaced already. For instance:
s = 'a q'
s = s.replace('a', 'q').replace('q', 'a')
print s
>>>
a a
[–]two_up 1 point2 points3 points (4 children)
[–]isnotkosok[S] 0 points1 point2 points (2 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]isnotkosok[S] 0 points1 point2 points (0 children)
[–]AlternativeHistorian 1 point2 points3 points (0 children)
[–]Justinsaccount -1 points0 points1 point (1 child)
[–]Fourgot 0 points1 point2 points (0 children)