One liner using itertools.combinations()
import itertools l1 = [3,4,5] l2 = [4,5,7] l3 = [5,6,7,8,3] L = [l1, l2, l3] verdict = all([len(a)==len(b) for a,b in list(itertools.combinations(L,2))])
First, compile a list of the list, L Then query all sets of two elements from L using list(itertools.combinations(L,2)) :
>>> list(itertools.combinations(L,2)) [([3, 4, 5], [4, 5, 7]), ([3, 4, 5], [5, 6, 7, 8, 3]), ([4, 5, 7], [5, 6, 7, 8, 3])]
Then check the lengths for each pair in this list. Finally, take the intersection of booleans, with all() .
>>> verdict False
It is right. Try using lists of attempts of the same size.
l1 = [3,4,5] l2 = [4,5,7] l3 = [5,6,7] L = [l1, l2, l3] verdict=all([len(a)==len(b) for a,b in list(itertools.combinations(L,2))])
we get
>>> verdict True