Worked Examples · Example 9.2
Q.Example 9.2: Given the nested list list1 = [1,2,'a','c',[6,7,8],4,9], access the inner list with list1[4] and access an element of the nested list using two indices list1[i][j] (e.g., list1[4][1]).
Tamil Nadu DgeTextbookSubjective· 2mImportance★★★★★est
12% · 3/26 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →In a nested list, list1[i] returns the inner list at position i, and list1[i][j] digs one level deeper to return element j of that inner list — so list1[4] is [6, 7, 8] and list1[4][1] is 7.
The idea (nested lists and double indexing). A list element can itself be a list. Indexing works one level at a time: the first subscript selects the element of the outer list; if that element is again a list, a second subscript selects from it. Think of list1[4][1] as (list1[4])[1] — first fetch, then index the fetched object.
Program
list1 = [1, 2, 'a', 'c', [6, 7, 8], 4, 9]
# access the inner (nested) list
print(list1[4])
# access an element of the nested list: row index 4, inner index 1
print(list1[4][1])
Expected output
[6, 7, 8]
7
Step by step
| Expression | What Python does | Result |
|---|---|---|
| list1[4] | takes the element at index 4 of the outer list | [6, 7, 8] |
| list1[4][1] | takes index 1 of that inner list | 7 |
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.