Reverse Words in String
Reverse order of words in string.
AdvancedPhase 5 - Category 5: Advanced String LogicExample 14 of 14
reverse-words-in-string.py
1# Take string2s = input("Enter string: ")34# Reverse words5words = s.split()6reversed_words = words[::-1]7result = ' '.join(reversed_words)89print(f"Reversed: {result}")
Output
Enter string: Hello World Programming Reversed: Programming World Hello
What's going on
Split, reverse list, join.
Key Concepts:
Split into words
Reverse word list
Join with spaces
🔗Related Content
- 📖
Phase 5 - Learn Concepts
Review Phase 5 concepts and explanations
- 📝
Phase 5 - Quiz
Test your Phase 5 understanding with quiz questions
- 💻
Phase 5 - All Practice Problems
Explore all practice problems for Phase 5
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum