Check Anagram
Check if two strings are anagrams.
AdvancedPhase 5 - Category 5: Advanced String LogicExample 1 of 14
check-anagram.py
1# Take two strings2s1 = input("Enter first string: ").lower().replace(" ", "")3s2 = input("Enter second string: ").lower().replace(" ", "")45# Check anagram6if sorted(s1) == sorted(s2):7 print("Anagrams")8else:9 print("Not anagrams")
Output
Enter first string: listen Enter second string: silent Anagrams
What's going on
Sort both strings and compare.
Key Concepts:
Convert to lowercase
Remove spaces
Sort and compare
🔗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