I would do that this way:
- Scan the file in order to find the minimum and maximum row and column indices. For simplicity sake, let's say the minima are zeroes and maxima are
max_row
and max_col
. - Create a bidimensional list having
(max_row + 1)
rows and (max_col + 1)
columns. Initialise all the items of the bidimensional list with 0
. - Scan the file again, assigning the proper value to the corresponding item of the bidimensional list (e.g.
0 3 .92
=> m[0][3] = .92
.
That's all, folks.
[update]
Fixed the wrong column index, thanks to
Patrice T.
[/update]