Reverse even length word in a string



Problem to reverse the even length word only.



Example-1:


Input    : s = "my crazy coding"
Output   : ym crazy gnidoc 
Explain  : The word "my" and "coding" length is even.So reverse that words only.


Example-2:


Input    : s = "I am happy"
Output   : I ma happy 
Explain  : The word "am" length is even.So reverse that word only.







Solution




s = "my crazy coding"

s = s.split()

d = ""

for x in s:

    if(len(x) % 2 == 0):

        d += x[::-1]

        d += " "

    else:

        d += x

        d += " "

print(d.strip())



Output



ym crazy gnidoc