Question
k = [2, 1, 0, 3, 0, 2, 1]
print(k.count(k.index(0)))
Solution
The given list is k = [2, 1, 0, 3, 0, 2, 1].
k.index(0) finds the index of the first occurrence of the value 0 in the list k. In this case, the first occurrence of 0 is at index 2.
The result of k.index(0) is 2.
k.count(2) counts how many times the value 2 appears in the list k.
In the list k, the value 2 appears twice, at index 0 and index 5.
So, the final result is 2 because the index of the first occurrence of 0 (which is 2) appears twice in the list k.
0 Comments:
Post a Comment