import re
s = 'я яяя, ты тытыты'
replaces = {'я': 'ты', 'ты': 'я'}
s_replaced = re.sub(r'(^|(?<=\s))(я|ты)((?=\s)|$)', lambda m: replaces.get(m.group(), m.group()), s)
print('{0} -> {1}'.format(s, s_replaced))
aW1wb3J0IHJlCnMgPSAn0Y8g0Y/Rj9GPLCDRgtGLINGC0YvRgtGL0YLRiycKcmVwbGFjZXMgPSB7J9GPJzogJ9GC0YsnLCAn0YLRiyc6ICfRjyd9CnNfcmVwbGFjZWQgPSByZS5zdWIocicoXnwoPzw9XHMpKSjRj3zRgtGLKSgoPz1ccyl8JCknLCBsYW1iZGEgbTogcmVwbGFjZXMuZ2V0KG0uZ3JvdXAoKSwgbS5ncm91cCgpKSwgcykKcHJpbnQoJ3swfSAtPiB7MX0nLmZvcm1hdChzLCBzX3JlcGxhY2VkKSk=