例如,当我必须比较两个类似数组的对象的内容时list
s, tuple
s or collection.deque
s -- 不考虑对象的类型,我使用
list(an_arrayish) == list(another_arrayish)
有没有更惯用/更快/更好的方法来实现这一目标?
按元素比较:
def compare(a,b):
if len(a) != len(b):
return False
return all(i == j for i,j in itertools.izip(a,b))
对于 Python 3.x,使用zip
instead
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)