how do i print the second letter first and then the first word in python?

One simple approach would be the following (recursive) function:

def reverse_chunks(s, n=2):
    if not s:
        return s
    return s[:n][::-1] + reverse_chunks(s[n:])

>>> reverse_chunks("stackoverflow")

Of course, there are more performant iterative approaches.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top