<p>当前正在运行:</p>
<pre><code>l1 = [i for i in range(0,10)]
l2 = [i for i in range(0,10)]
l3 = [i for i in range(0,10)]
lists = [l1, l2, l3]
length = len(lists[0])
for l in lists:
if length != len(l):
raise ValueErrorr('not all lists have same length!')
</code></pre>
<p>有没有比<code>for</code>循环更好的测试方法?有没有一种更快/更好的方法不是<code>O(n)</code>?在</p>
<p>首先,您的解决方案不是O(logn)。不可能有对数算法。你必须至少检查一次每一项,所以O(n)是最佳的复杂度。在</p>
<pre><code># import imap from itertools on Py2
if len(set(map(len, lists))) not in (0, 1):
raise ValueErrorr('not all lists have same length!')
</code></pre>