22
Phase 5 - Category 4: Character & Word Manipulation
Chapter 22 • Intermediate
90 min
Phase 5 - Category 4: Character & Word Manipulation
Introduction
Learn to manipulate strings by removing, replacing, and transforming characters and words based on various conditions.
Key Concepts
Character Removal
- Remove Vowels: Delete all vowels
- Remove Spaces: Delete all spaces
- Remove Digits: Delete all digits
- Remove Duplicates: Keep only first occurrence
Character Replacement
- Replace Vowels: Replace with specific character
- Replace Spaces: Replace with underscore or other
- Swap Case: Convert uppercase to lowercase and vice versa
- Shift Characters: Move characters by positions
Word Manipulation
- Remove Duplicate Words: Keep unique words
- Remove Consecutive Duplicates: Remove repeated words
- Capitalize Words: First letter uppercase
- Title Case: Each word capitalized
Common Operations
Remove Characters
python.js
result = ""
for char in text:
if char not in to_remove:
result += char
Replace Characters
python.js
result = text.replace(old_char, new_char)
Remove Duplicates
python.js
seen = set()
result = ""
for char in text:
if char not in seen:
result += char
seen.add(char)
Problem-Solving Approach
- Iterate: Loop through characters or words
- Check Condition: Should character/word be kept or modified?
- Build Result: Construct new string
- Handle Edge Cases: Empty string, all same characters
Hands-on Examples
Remove Vowels
# Take string input
text = input("Enter a string: ")
# Remove vowels
vowels = "aeiouAEIOU"
result = ""
for char in text:
if char not in vowels:
result += char
print(f"String without vowels: {result}")Iterate through string, add character to result only if it is not a vowel. Build new string character by character.
Related Tutorials
🔗Related Content
- 💻
Phase 5 - Practice Problems
Practice Phase 5 concepts with hands-on coding problems
- 📝
Phase 5 - Quiz
Test your Phase 5 understanding with assessment questions
- ➡️
Phase 6 - Get Started
Continue to Phase 6 after mastering Phase 5
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum