Iterate over the ranges
for i in range ( r ) : NEW_LINE INDENT c = 0 NEW_LINE l , h = ranges [ i ] [ 0 ] , ranges [ i ] [ 1 ] NEW_LINE for val in arr : NEW_LINE INDENT if l <= val <= h : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT a . append ( c ) NEW_LINE DEDENT return a NEW_LINE