-4

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.

Micheal C
  • 29
  • 5

1 Answers1

1

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

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219