Reverse odd places words in a string



Problem to reverse the words which has odd places.



String  : "welcome to hello world"
places  :     1     2   3     4



Example-1:


Input    : s = "welcome to hello world"
Output   : emoclew to olleh world


Example-2:


Input    : s = "my crazy coding"
Output   : ym crazy gnidoc







Solution




s = "welcome to hello world"

s = s.split()

d = ""

for i in range(len(s)):

    if(i % 2 == 0):

        d += s[i][::-1]

        d += " "

    else:

        d += s[i]

        d += " "

print(d.strip())



Output



emoclew to olleh world