Wednesday, June 10, 2015

Reverse each word in a sentence - Python

# your code goes here

st = "This is awesome!"

st1 = st.split(" ")
st2 = ''
st3 = []

print st1

for y in st1:
#print y
ls = len(y)
for x in range(len(y)):
st2 = st2 + y[ls - 1 -x]
st2 = st2 + ' '
st3.append(st2)
print ' '.join(st3)

No comments:

Post a Comment