Measure a Collection with len
Count the elements directly inside the outer sequence.
About 18 minutes, plus any extended practice
Supplied materials
- Paper and pencil; answers may also be spoken or typed.
- All cases, labels, numbers and rules are supplied on this page. No real account, private information or purchase is needed.
Learn the idea
The Python len function reports how many items a sequence contains. For a list, each element is one item, even when an element is itself a list. Counting outer items differs from adding their numeric values or counting all nested contents. These supplied expressions make the nesting visible.
Count the elements directly inside the outer sequence. Do not replace list length with the sum of its values.
Use this supplied case: Paper Python 3 expression: len([2,5,9]). What value results? The task is to connect the given information to the computing idea. Write a short evidence trail so another learner can reproduce your choice. The simplified case describes the stated model, not every real system.
- Represent the supplied worked case with a labeled drawing, table or short trace.
- Count the elements directly inside the outer sequence.
- Explain why the worked answer fits and why one alternative does not.
- Try the new check and practice cases; revisit the stated rule if your evidence does not match.
See the method in action
The list [2,5,9] has three outer elements, so its length is 3, rather than their sum 16. The distinct nested list [[8],[4,6,2],[1,5]] also has three outer elements: the first, second and third inner lists. The six numbers inside those lists do not change the outer length to six. Counting outer elements differs from recursive counting. An empty collection has no outer elements; identify which collection is being measured.
Check your reasoning
Your answer is temporary and is not saved to an account. Download your current answer before leaving or reloading. Written work on paper or in another app stays in your own file.
Helpful tips
- Count the elements directly inside the outer sequence.
- Do not replace list length with the sum of its values.
See the answer and explanation
2
The outer sequence is [8, 1]. It contains 2 directly enclosed elements, so len returns 2. Nested contents, if any, do not increase the outer count. Count the elements directly inside the outer sequence.
Take it further
For values=[[1, 2, 3], [], [4]], expected len(values)=3 outer items. Nested contents do not increase the outer list length.
Nothing here is saved to an account or sent to a teacher. The answer download includes your current choice and any checked feedback. It does not include choices from the separate More practice section. Download that section separately.
More practice: try new cases
Choose an answer for each problem. Explain your method on paper, then use the feedback to decide what to revisit.
Your choices are temporary. Feedback appears after you check all the answers.
Nothing here is saved to an account or sent to a teacher. Keep your own notes or download them before leaving. The score describes these questions; it does not certify subject mastery.
Check the subject sources
These LifeStarter passages, scenarios and exercises are authored for this Academy with AI assistance and review. External resources keep their publishers’ terms. A grade label suggests a starting level; it does not establish alignment with your school’s complete requirements.