import reprint (re.subn("(a)(n)", lambda m: "{}{}".format(m.group(2), m.group(1)), "banana"))
Standard input is empty
('bnanaa', 2)
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!