[Tutor] function with multiple checks

Tim Miller tim at lashni.net
Mon Sep 27 18:52:43 CEST 2010

> set does seem to have what you want: isdisjoint() could do the trick.
> Eg:
>      if set(punctuation).isdisjoint(password) or set(digits).isdisjoint(password) or set(ascii_uppercase).isdisjoint(password) or set(ascii_lowercase).isdisjoint(password):
>           return False
>      return True
> You could even confuse yourself and put it all on one line:
>        return not any(set(chars).isdisjoint(password) for chars in [punctuation, digits, ascii_uppercase, ascii_lowercase])
> but I wouldn't recomended it. I guess this can even shortened further.
> (note: the 'not' operator is needed, because isdisjoint returns True for what you probably prefer as False.)

Here I was thinking I'd read through set types thoroughly and now that 
you've pointed out isdisjoint it really jumps out describing exactly the 
usage I was looking for.


     Return True if the set has no elements in common with other. Sets 
are disjoint if and only if their intersection is the empty set.

More information about the Tutor mailing list