我有一系列形式的条件句:表达式在字典映射
if ':' in particle:
do something
elif 'eq' in particle:
do something else
elif 'lt' in particle:
do another thing
elif 'le' in particle:
etc.
elif 'gt' in particle:
etc., etc.
elif 'ge' in particle:
etc., etc., etc.
elif 'ne' in particle:
more etc.
我想实现这个使用字典映射模式,但我的钥匙有问题。
我尝试这样做:
def case_evaluator(particle):
switcher = {
':' in particle: do something,
'eq' in particle: do something else,
'lt' in particle: do another thing,
...
}
return switcher.get(particle, "nothing")
但是,我一直得到 “什么都没有。”怎么能一无所获?
这似乎应该是简单的,但很可惜......
不宜“的说法”在某处声明? – phenxd
对不起......我刚刚编辑过这个。 –