Filling a diagonal matrix based on selectors
<p>I have two lists:</p>

<pre><code>[(1, 0), (2, 0), (2, 1), (3, 0), (3, 1), (3, 2)]

[False, False, True, False, False, False]
</code></pre>

<p>The first list represent the row_number, column_number of the matrix. The second list represent the element value. How can I create an efficient loop(or other algorithm) so I end up with a 4 by 4 matrix:</p>

<pre><code>0 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0 
</code></pre>

<p>Does this have to actually be a numpy-like matrix? Seems to me you could do something like:</p>

<pre><code>coords = [(1, 0), (2, 0), (2, 1), (3, 0), (3, 1), (3, 2)]
values = [False, False, True, False, False, False]

DEFAULT_VALUE = 0

height, width = max(coords)[0], max(coords, key=lambda x_y:x_y[1])[1]
matrix = [[DEFAULT_VALUE for _ in range(width)] for _ in range(height)]
for coord, value in zip(coords, values):
    y, x = coord
    matrix[y][x] = value
</code></pre>

python python-3.x