import re
print (re.subn("(a)(n)", lambda m: "{}{}".format(m.group(2), m.group(1)), "banana"))