The semantics of list operators are congruent, but unintuitive sometimes.
For example, I've fallen over this many times:

>>> truth_matrix = [[False] * n ] * m


It doesn't create what you'd want.

The only safe way I know to creat an NxM matrix is:

>>> truth_matrix = [ [False for _ in range(n) for _ in range(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.

`numpy` is not part of stdlib. A standard library for list of list would be
usefu, specially to newcomersl. I don't remember such being discussed
lately.

>>> truth_matrix = lol(n, m, init=bool)

>>> other_matrix = lol(n, m, o, p, init=float)


Maybe it could also be done with syntax, but I don't have any ideas in that
regard (I don't think "lol()" is overloaded).

Regards,

-- 
Juancarlo *Añez*
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to