Hey I'm trying to write a function that only prints a list that contains no zeros in a list of lists. Here is a sample of the list of lists I am working with:
[['10011.0', ' 65301.0', ' 0.085', ' 0.0', ' 0.0', ' 0.0', ' 0.03', ' 0.03', ' 0.075',
' 0.05', ' 0.065', ' 0.05', ' 0.05', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0'],
['10017.0', ' 2743.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.2', ' 0.413333', ' 0.415', ' 0.3125', ' 0.45', ' 0.46', ' 0.55'],
['10017.0', ' 9262.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.35', ' 0.69', ' 0.675', ' 0.8075', ' 0.8075', ' 0.5325', ' 0.785'],
['10017.0', ' 29319.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0225', ' 0.06', ' 0.0575', ' 0.105', ' 0.1', ' 0.045', ' 0.0'],
['10017.0', ' 43562.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.0', ' 0.106667', ' 0.0925', ' 0.09', ' 0.1', ' 0.09', ' 0.1025'],
['10017.0', ' 43563.0', ' 1.0', ' 1.0', ' 1.0', ' 1.0', ' 1.0', ' 1.0', ' 1.0', ' 1.0', ' 1.0', ' 1.0', ' 1.0', ' 0.106667', ' 0.0925', ' 0.09', ' 0.1', ' 0.09', ' 0.1028']]
The code I am running is:
def no_zero(A):
for i in range(len(A)):
for j in range(2, (len(A[i])+1)):
if '0.0' not in A[i]:
print A[i]
break
For some reason it does not filter any of the lists and prints the entire list of lists despite the conditional: "if '0.0' not in A[i]:" I am unsure where my error is because it seems like the logic should be fairly straightforward. Thanks for any help!
forloop? You never usejanywhere.janywhere in your code. You also don't want to uselen+1as your termination point, becauseA[len(A)]never exists.