Convert String to Array of Digits
Convert string of digits to array.
IntermediatePhase 6 - Category 2: Array & String CombinationsExample 2 of 10
convert-string-to-array-of-digits.py
1# Take string2s = input("Enter a string of digits: ")34# Convert to array5arr = [int(char) for char in s if char.isdigit()]6print(f"Array: {arr}")
Output
Enter a string of digits: 12345 Array: [1, 2, 3, 4, 5]
What's going on
Convert each digit character to integer.
Key Concepts:
Check if character is digit
Convert to int
Create list
🔗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