Thursday 13 August 2020

Reverse the internal content of each word

 

 

 

Sample Input: Hello Python

Output: olleH nohtyP

 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
string_data=input("Enter a string: ")
list1=string_data.split()
print(list1)
list2=[]
for word in list1:
	list2.append(word[::-1]) # Reversing word and then adding to list2
print(list2)
result=" ".join(list2)
print("The string you entered:", string_data, sep="\n")
print("The result after reversing order of words in the string: ", result, sep="\n")

 

No comments:

Post a Comment