When I initialize the check_dict
, will all the values(condition) be calculated(become boolean values), if yes will it be not efficient if I put conditon be dictionary's value, is there any better way to do it?
def checker(fruit: str, number: int) -> bool:
check_dict = {
"apple": True if number > 3 else False,
"banana": True if number < 2 else False,
"watermelon": True if number > 10 else False
}
res = check_dict.get(fruit, None)
if res:
return res
ans = checker(fruit="apple", number=4)
print(ans)
source https://stackoverflow.com/questions/73847475/python-initialize-a-dictionary-with-condition-values
Comments
Post a Comment