Reverse Each Word

Reverse each word in string.

Logic BuildingIntermediate
Logic Building
# Take string input
s = input("Enter a string: ")

# Reverse each word
words = s.split()
reversed_words = [word[::-1] for word in words]
result = " ".join(reversed_words)

print(f"Result: {result}")

Output

Enter a string: Hello World
Result: olleH dlroW

Reverse each word individually.

Key Concepts:

  • Split into words
  • Reverse each word using [::-1]
  • Join back with space