10.23. Nested Lists¶
A nested list is a list that appears as an element in another list. In this
list, the element with index 3 is a nested list.
If we print(
nested), we get
[10, 20]. To extract an element from the
nested list, we can proceed in two steps. First, extract the nested list, then extract the item
of interest. It is also possible to combine those steps using bracket operators that evaluate from
left to right.
Check your understanding
- 6 is in the wrong list. alist refers to the second item in alist, namely [888,999].
- 8 is in the wrong list. alist refers to the second item in alist, namely [888,999].
- Yes, alist is True and alist is the second list, the first item is 888.
- alist is True. Take another look at the if statement.
list-23-1: What is printed by the following statements?
alist = [ [4, [True, False], 6, 8], [888, 999] ] if alist: print(alist) else: print(alist)