Given a list of lists:
>>> n=4
>>> LoL=[range(n) for i in range(n)]
>>> LoL
[[0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3]]
Is it readily apparent, understandable, Pythonic even to assure a N x N matrix this way:
>>> len(LoL) == n and {len(l) for l in LoL} == {n}
True
So it would be used thus:
if len(matrix) != 4 or {len(l) for l in matrix} != {4}:
raise ValueError
Is there a better alternative idiom or is this understandable?
As stated in your comment, try / except is probably better.
Not only will you catch and attempt to use an element outside of the 4×4 size, but you will also catch the wrong dimensions passed to you:
Vs, if you have doubt about the data you are about to use: