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

Joel Goldstick joel.goldstick at gmail.com
Sun Mar 21 04:07:12 EDT 2021


On Sun, Mar 21, 2021 at 3:16 AM Manprit Singh <manpritsinghece at gmail.com> wrote:
>
> Dear sir ,
> take two lists
>
> 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 ?
> This
> set(lst1).isdisjoint(set(lst2))
> Or This
> set(lst1).isdisjoint(lst2)
>
> Regards
> Manprit Singh
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

It looks like the l2 can be a list
>>> l1 = [1,2,3]
>>> l2 = [2,4,7]
>>> set(l1).isdisjoint(l2)
False
>>>



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays


More information about the Tutor mailing list