[Tutor] consider a problem of finding if two lists have any item in common

Mats Wichmann mats at wichmann.us
Sun Mar 21 11:01:18 EDT 2021


On 3/21/21 8:53 AM, Peter Otten wrote:
> On 21/03/2021 09:52, Alan Gauld via Tutor wrote:
>> On 21/03/2021 07:15, Manprit Singh wrote:
>>
>>> lst1 = [2, 4, 6, 9]
>>> lst2 = [2, 5, 9, 0]
>>> this can be done using isdisjoint(other), it will return True if the 
>>> lists
>>> have no items in common .The official documentation says nothing about
>>> other , just need to know if other can be an iterable or it should 
>>> strictly
>>> be a set or frozenset?
>>> what should be the correct way ?
>>
>> Don't ask us, ask the interpreter, it knows best.
>> And it gives faster answers too.
>>
>> If its answers aren't what you'd expect *then* ask us why?

I'd perhaps also note that while the answer to the question asked may 
indeed be interesting, a lot of the time you actually want to know 
_what_ they have in common, and that would be a different operation. 
Which you can always truth-test to find out if they indeed had any 
common members.




More information about the Tutor mailing list