我需要以下功能:
输入:alist
输出:
True 如果输入列表中的所有元素使用标准相等运算符评估为彼此相等; False 除此以外.性能:当然,我不希望招致任何不必要的开销.
我觉得最好是:
AND所有结果布尔值但我不确定最恐怖的方式是什么.
编辑:
谢谢你所有的好答案.我评价了几个,而且很难在@KennyTM和@Ivo van der Wijk解决方案之间做出选择.
缺少短路功能只会对早期具有不相等元素的长输入(超过约50个元素)造成伤害.如果这种情况经常发生(通常取决于列表的长度),则需要进行短路.最好的短路算法似乎是@KennyTM checkEqual1.然而,它为此付出了巨大的代价:
如果早期不等元素的长输入没有发生(或很少发生),则不需要短路.然后,到目前为止最快的是@Ivo van der Wijk解决方案.
我需要验证我的列表列表是否在python中具有相同大小的列表
myList1 = [ [1,1] , [1,1]] // This should pass. It has two lists.. both of length 2
myList2 = [ [1,1,1] , [1,1,1], [1,1,1]] // This should pass, It has three lists.. all of length 3
myList3 = [ [1,1] , [1,1], [1,1]] // This should pass, It has three lists.. all of length 2
myList4 = [ [1,1,] , [1,1,1], [1,1,1]] // This should FAIL. It has three list.. one of which is different that the other …Run Code Online (Sandbox Code Playgroud)