Technical skill practice
Python List Length: Count Top-Level Items with len
Use len(your_list) to get a Python list’s length. It counts the list’s top-level items. An inner list occupies one position regardless of how many entries it contains, so a nested timetable’s outer length is not the total number of appointments.
Start with a small, explicit task
Represent three timetable days as inner lists, including one empty day. Compare the number of days with the sum of the appointment counts. Add a fourth empty day and inspect which total changes. No scheduling system is involved: these short strings are synthetic labels for the counting exercise.
Run the complete example
This original example was checked with Python 3.12.14. Save it as python_list_length.py and run it with Python 3.12. It uses only the standard library. The assertions check the stated results.
Expected output
days: 3 -> 4
appointments: 3
empty: 0
timetable = [["check-in", "review"], [], ["handover"]]
days_before = len(timetable)
slots_before = sum(len(day) for day in timetable)
timetable.append([])
assert days_before == 3 and slots_before == 3
assert len(timetable) == 4
assert sum(len(day) for day in timetable) == 3
assert len([]) == 0
print("days:", days_before, "->", len(timetable))
print("appointments:", slots_before)
print("empty:", len([]))
Explain the result
Initially the outer list has three items: two populated day lists and one empty day list. The appointment total is calculated separately as 2 + 0 + 1. Adding another empty day increases the outer count to four without increasing the appointment count. That difference is the main question this example isolates.
days_before stores an integer obtained at that moment. It does not keep a live connection to the list, which is why the final print can show both the old and new counts. Call len again when you need the current length. Counting one additional level with sum is appropriate for this stated two-level structure; it is not a general recursive flattening algorithm.
Avoid these mistakes
Do not call list.length or count() without a value to obtain the total size. list.count answers how many entries equal a particular value. Also avoid using len(list) - 1 as an index without checking for empty input; a count of zero means there is no last element to access.
Questions, answered
Does len count items inside nested lists?
It counts only the outer positions here. Calculate inner counts separately when that is the intended unit.
Will a saved length update automatically?
No. It is the integer returned at the time of the call. Request len again after changes.
Sources and examples
ResumizeAI team. Examples are fictional teaching material, not customer results. Replace sample details with your own facts.
Your experience. A complete resume.
Build in Resumize with ATS-friendly templates, guided editing and a live preview. Start free, then upgrade when you need more.
Free account required. Free-plan PDF exports include a watermark.