Array of Palindrome Strings
Check which strings in array are palindromes.
IntermediatePhase 6 - Category 2: Array & String CombinationsExample 5 of 10
array-of-palindrome-strings.py
1# Take array of strings2n = int(input("Enter number of strings: "))3arr = []4for i in range(n):5 arr.append(input(f"String {i+1}: "))67# Find palindromes8palindromes = []9for s in arr:10 if s == s[::-1]:11 palindromes.append(s)1213print(f"Palindromes: {palindromes}")
Output
Enter number of strings: 4 String 1: hello String 2: racecar String 3: world String 4: level Palindromes: ['racecar', 'level']
What's going on
Check each string for palindrome property.
Key Concepts:
Compare string with reverse
Add to list if palindrome
Filter palindromes
🔗Related Content
- 📖
Phase 6 - Learn Concepts
Review Phase 6 concepts and explanations
- 📝
Phase 6 - Quiz
Test your Phase 6 understanding with quiz questions
- 💻
Phase 6 - All Practice Problems
Explore all practice problems for Phase 6
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum