This module practices storing sequences, iterating them, and computing frequencies.
Learning Metadata
- Difficulty: Beginner.
- Estimated Time: 20-35 minutes.
- Prerequisites:
01-foundations/control-flow,01-foundations/functions. - Cross-Language Lens: Compare
vector,List<T>, slices, and Python lists as different tradeoffs for dynamic sequence handling.
Learning Outcomes
FND-SEQ-01: Store and traverse ordered collections safely.FND-SEQ-02: Handle empty collections and index boundaries explicitly.
Quick Run
Run from the repository root:
python scripts/automation.py run-module --module-path languages/python/01-foundations/arrays-and-vectors
Topics Covered
- Building dynamic collections from user input.
- Forward and reverse iteration patterns.
- Counting occurrences of a target value.
- Handling empty or invalid-size collections.
Common Pitfalls
- Trusting collection size input when count is zero or negative.
- Off-by-one errors while reading N elements.
- Not handling empty input in frequency tasks.
Cross-Language Notes
- In Python, read this module through the native focus ?Lists and Sequences?; the shared folder name remains stable for side-by-side navigation.
- Use dynamic values, collection protocols, and context managers to demonstrate how to store and traverse ordered collections safely.
- Compare observable behavior with the other tracks when learning to handle empty collections and index boundaries explicitly; equivalent evidence matters more than identical syntax.
Exercise Focus
- exercises/01.py: read N integers, store them, and print them in reverse order.
- exercises/02.py: read a collection and count frequency for a target integer.
Exercise Specs
- exercises/01.py
- Input: positive integer count and then count integers.
- Output: values printed in reverse insertion order.
- Edge cases: count <= 0; repeated values in the collection.
- exercises/02.py
- Input: integer list plus a target integer.
- Output: frequency count for target value.
- Edge cases: empty list input; target not present.
Check Your Work
Run from the repository root after implementing a starter:
python scripts/automation.py check-exercise --language python --level 01-foundations --module arrays-and-vectors --exercise 01
Change --exercise 01 to --exercise 02 for the second task. Consult exercises/solutions/ only after making a complete attempt.
Checkpoint
- I can explain the core ideas of this module.
- I can run and modify example/main.py.
- I completed exercises/01.py.
- I completed exercises/02.py.
- I validated at least one edge case for each exercise.
Content revision 1d0b3f4