>>> truth_matrix = [[False] * n ] * m
There could be a library to deal with that common case, and those of checking if a list of lists (of lists?) is properly rectangular, square, etc., and several other common cases. It takes experience to be aware that `truth_matrix[i][j]` will change more than one "cell" if the initialization is the former.>>> truth_matrix = [ [False for _ in range(n) for _ in range(m)]
>>> truth_matrix = lol(n, m, init=bool)
>>> other_matrix = lol(n, m, o, p, init=float)
Or maybe there is one in PyPi — have you looked?There's a bunch of "matrix" packages in PyPi, none of them dealing with the simple use cases I'm talking about.
It could be static methods in `list`?x = list.matrix(n, m, default=0.0)y = list.matrix(n, m, o, p, default=False)i = list.eye(n, False, True)
> ipython
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: [[False]*2]*5
Out[1]:
[[False, False],
[False, False],
[False, False],
[False, False],
[False, False]]
# Looks like exactly what was wanted