Shift word to right and then reverse it.
You should take a word shift to right and reverse it then return as follows:
>>> shift_reverse('Introduction to Computer Programming')
gnimmargorP noitcudortnI ot retupmoC
I tried using this method to find the above answer but it doesnt seem to work Please help :(
s= "I Me You"
def shift_reverse(s):
l= s.split()
new_str= ' '.join(l[-1:] + l[:-1])
new_str = new_str[::-1]
return (new_str)
print (shift_reverse(s))
but the print i get is
[evaluate untitled-3.py]
eM I uoY
You need to reverse each of the re-ordered list:
reordered = l[-1:] + l[:-1]
new_str = ' '.join(word[::-1] for word in reordered)
You can join a generator expression that generates reversed words in the rotated split list:
>>> s = 'Introduction to Computer Programming'
>>> ' '.join(w[::-1] for w in (lambda l: l[-1:] + l[:-1])(s.split()))
'gnimmargorP noitcudortnI ot retupmoC'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With