This is the lecture note of CS61A - Lecture 12.
Processing Container Values
- sum(iterable[, start=0]) -> value
- max(iterable[, key=func]) -> value, min(iterable[, key=func]) -> value
- all(iterable) -> bool
- any(iterable) -> bool
1 | # Aggregation |
Trees
Tree is an important data abstraction for representing hierarchical relationship.
1 | # Trees: recursive implementation |
Tree Processing
1 | ### +++ === ABSTRACTION BARRIER === +++ ### |
One more example:
1 | def print_tree(t, indent=0): |
Example 1: Summing Paths
First, let's see an example of tail recursion.
1 | # Order |
Then use this strategy to solve print_sums
question.
1 | from tree import * |
Example 2: Counting Paths
1 | # Count paths that have a total label sum |