How can I define a function that splits a string into 2 parts, and reverses them both? If the string is odd, it leaves the middle character (remainder) alone.
For example:
revStr(“ “)
revStr(“xy“)
revStr(“wxyz“)
revStr(“vwxyz“)
revStr(“uvwxyz“)
revStr(“tuvwxyz”)
would output:
xy
xwzy
wvxzy
wvuzyx
vutwzyx
I have tried this, but I can't even get the even strings to flip correctly...
def revStr(string):
output = " "
start = 0
if len (string) % 2 == 0:
x = string[start:start//2]
y = x[::-1]
string = x+y
return(string)
printrevStr("abcdef")
Needing some guidance or ideas for this, thanks in advance! Let me know if there is anything I can clarify.