在我的 python 代码中,我将一些 bool() 转换为我知道可能已经是布尔值的变量。这有什么缺点吗?(性能等)
这是我正在使用的函数的基本克隆。
import re
pattern= "[A-Z]\w[\s]+:"
other_cond= "needs_to_be_in_the_text"
def my_func(to_check: str) -> bool:
res = re.search(pattern, to_check)
res2 = other_cond in to_check
return bool(res), bool(res2) # res2 either None or True
# I need boolean returns because later in my code I add all these
# returned values to a list and use min(my_list) on it. to see if
# there's any false value in there. min() on list with None values causes exception
慕慕森
相关分类