# Finding subset of lists with common entries

Suppose I have a list of lists. For example,

[ [1, 2, 3, 4], [1, 3, 1, 3], [4, 1, 4, 1], [1, 3, 2, 1], [4, 1, 2, 4] ]

I want SageMath to give me a sub-list of this list that consist of lists where any two have at least one common entry. For example,

[ [1, 2, 3, 4], [1, 3, 1, 3], [1, 3, 2, 1] ]

or

[ [4, 1, 4, 1], [1, 3, 2, 1], [4, 1, 2, 4] ] .

What would be even more amazing is if SageMath could find the largest possible such sub-list. How could I get SageMath to do this? Thank you in advance!

Does "having a common entry" for two lists

`A`

and`B`

mean`set(A).intersection(set(B)) != set()`

or`any(a == b for a,b in zip(A,B))`

(assuming`A`

and`B`

have the same length)?If you can describe an algorithm, then the code should not be hard to write. What algorithm do you have in mind?

By "having a common entry" I mean that the lists have to have the same value in the same column. For example, [1, 2, 3, 4] and [1, 3, 1, 3] both have 1 as entry 1. I honestly don't even know where to begin to come up with an algorithm for this. Whatever I come up with seems convoluted.