How to count the number of elements in a list that are less than or equal to a specific value in Python

1 Answer

0 votes
import numpy as np

lst = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]

arr = np.array(lst)

print(np.count_nonzero(arr <= 7))
 
 
 
 
'''
run:
 
8
 
'''

 



answered Mar 20, 2023 by avibootz
...