【发布时间】:2016-06-27 13:43:20
【问题描述】:
我目前只使用这样的东西:
def match9(a,b,c,d,e,f,g,h,i):
if a==b and b==c and c==d and d==e and e==f and f==g and g==h and h==i:
return 1
else:
return 0
结合
temp = match9(d1s1,d1s2,d1s3,d1s4,d1s5,d1s6,d1s7,d1s8,d1s9)
if temp == 1:
codeToBeActivated()
【问题讨论】:
-
在什么方面更有效率?时间?空间?还是代码?
-
你不应该首先使用
==来比较floats。 -
好吧,看来您想检查所有项目是否相等,所以您只需
set()以保留唯一项目并计算结果长度。 -
def match9(*args): return functools.reduce(lambda x, y: x == y, args)- 不过,是的,==和浮点数不能很好地混合。
标签: python python-3.x