I'd like to count the number of non integers in double array. For example
Input: mylist=[['a',-2,'b',-3,1],['c','a',-1,1,3],['d','f'],['e',3],[-11]]
Output: num_value(mylist)=7
Show me how to make it.
Count instances of non-integers in the lists of lists (using double for
in generator comprehension fed to sum
)
mylist=[['a',-2,'b',-3,1],['c','a',-1,1,3],['d','f'],['e',3],[-11]]
print(sum(1 for sl in mylist for x in sl if not isinstance(x,int)))
yields: 7