我有以下布尔表达式:
not (start_date > b or s > end_date)
如何简化它?
def is_date_in_items(end_date, start_date, items):
b, s = _get_biggest_and_smallest_date(items)
return not (start_date > b or s > end_date)
答案 0 :(得分:6)
not (start_date > b or s > end_date)
// is equivalent to
not(start_date > b) and not(s > end_date)
// which is equivalent to
start_data <= b and s <= end_date
这来自De Morgan's Laws,其中指出:
¬(P OR Q) <=> (¬P) AND (¬Q)
答案 1 :(得分:1)
你可以缩短一点:
start_date <= b and s <=end_date