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.
isdisjoint(other)ΒΆ
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.
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor