I have a list and a list of list
A=["grp 1", "grp 2"]
B=[["1","2"],["3","4"],["5","6"]]
how do I check that each list in B is equal to the length of A?
I would like something like
if len(A) != len(list in B):
raise ValueError('special error message')
If you want to make sure that every single element of B is not equal to the length of A then you can use:
a_len = len(A)
all(len(x) != a_len for x in B)
Alternatively you can use the following if you want to see if any element of B is not the same length as A:
a_len = len(A)
any(len(x) != a_len for x in B)
So in your case you could use:
a_len = len(A)
if any(len(x) != a_len for x in B):
raise error
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With