logo CodeStepByStep logo

switch_pairs

Language/Type: Python string return

Write a function named switch_pairs that accepts a string as a parameter and returns that string with each pair of neighboring letters reversed. If the string has an odd number of letters, the last letter should not be modified. For example, the call switch_pairs("example") should return "xemalpe" and the call switch_pairs("hello there") should return "ehll ohtree".

Function: Write a Python function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.