I have an array as follow:
a = [1 2 5 3 8 7 2 9 8]
and a constant number b=4
How can I count the occurrence c
of a
being inferior to b
?
So in this example c=4
I have an array as follow:
a = [1 2 5 3 8 7 2 9 8]
and a constant number b=4
How can I count the occurrence c
of a
being inferior to b
?
So in this example c=4
If you mean "less than" by "inferior", you can use a list comprehension
c = len([x for x in a if x < b])
If you're worried about space constraints, you can use a generator like Alexander's answer.
sum(1 if num < b else 0 for num in a)