擅长:python、mysql、java
<h2>以下是我可以建议的两种方法:</h2>
<h2>1。简单for循环,这里我忽略了第一个和最后一个元素:(我猜这就是您需要的)</h2>
<pre><code>for i in array:
if any(x!="0" for x in i.split()[1:-1]): # here 1:-1 are the range where we are checking the values, you can edit it as per your need
print (i)
</code></pre>
<h2>2。同样使用列表理解</h2>
<pre><code>print ([i for i in array if any(x!="0" for x in i.split()[1:-1])])
</code></pre>
<h2>输出:</h2>
<pre><code>Port Align-Err FCS-Err Xmit-Err Rcv-Err UnderSize OutDiscards
Gi0/3 0 0 23 0 0 315887
Gi0/16 0 116 0 116 0 56
Po1 0 232464 0 232464 0 21331230
</code></pre>
<h2>增加了按要求操作的功能方式:</h2>
<pre><code>def getErrorList(array):
return [i for i in array if any(x!="0" for x in i.split()[1:-2])] #check the range [1:-2] carefully. Use it as per your need.
print (getErrorList(array)) #take it in a variable for further processing
</code></pre>