[Tutor] A program that can check if all elements of the list are mutually disjoint
Peter Otten
__peter__ at web.de
Sun Jun 6 04:51:41 EDT 2021
On 06/06/2021 10:19, Manprit Singh wrote:
> Dear sir ,
> Thanks to Roel . Finally today I have understood the importance of standard
> library modules, I work with mostly numbers when programming , and feel
> that itertools is very very useful.
> The solution that i do agree is as follows and seems readable to me too:
>
> import itertools
> def is_mutually_disjoint(arr):
> comb = itertools.combinations(lst, 2)
> return all(set(ele1).isdisjoint(ele2) for ele1, ele2 in comb)
Note that there's a bug in the above function (try running it with a
list literal) giving you a chance to learn why global variables should
be avoided ;)
More information about the Tutor
mailing list