Sort Words Alphabetically
Sort words in alphabetical order.
IntermediatePhase 5 - Category 3: Word OperationsExample 10 of 10
sort-words-alphabetically.py
1# Take string input2s = input("Enter a string: ")34# Sort words5words = s.split()6sorted_words = sorted(words)7result = " ".join(sorted_words)89print(f"Sorted: {result}")
Output
Enter a string: world hello programming Sorted: hello programming world
What's going on
Sort word list and join back.
Key Concepts:
Split into words
Sort using sorted()
Join with space
🔗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