Given a vector of vectors of some value T
, ie. Vec<Vec<T>>
.
What's the idiomatic way to check if the inner vectors have the same length? (without external dependencies)
That is, true
if all the inner vectors have the same length, and false
otherwise.
You can use the
all
method to check if all elements of an iterator match a predicate. Then just compare against the first element in the list.An other solution more generic and idiomatic in my opinion:
And of course using itertools: