Note 12.5.1. Lab.
-
Counting Letters Section 21.5 In this guided lab exercise we will work through a problem solving exercise that will use dictionaries to generalize the solution to counting the occurrences of all letters in a string.
matrix = [[0, 0, 0, 1, 0],
[0, 0, 0, 0, 0],
[0, 2, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 3, 0]]
http://en.wikipedia.org/wiki/Sparse_matrix
matrix = {(0, 3): 1, (2, 1): 2, (4, 3): 3}
[]
operator:
matrix[(0, 3)]
get
method solves this problem. The first argument will be the key. The second argument is the value get
should return if the key is not in the dictionary (which would be 0 since it is sparse).