I\'m writing a django model that allows my site to have coupons.
Coupons can have three types: lifetime account voucher, certain period of months voucher, certain numb
Even better solution than before, with combinations
, any
, and all
.
Assuming you have all the attributes you want to test in a sequence called attributes
:
from itertools import combinations
any(map(all, combinations(attributes, 2)))
In english, it reads
Are any length-2 combinations of the attributes all true?
This solution works for an arbitrary number of attributes, and can be modified to test for an arbitrary number of them being true.
Although admittedly it's very inefficient, I'd say it's pretty cute and readable.