After receiving the list, print the number of numbers in the specified range.
Input: [10, 20, 30, 40, 50 , 40, 40, 60, 70] range: 40-80 Output: 6 Input: [10, 20, 30, 40, 50, 40, 40, 60, 70] range: 10-40 Output: 4
Go through the list and check each number. If the number is in the specified range, then increase the counter. At the end of the traversal, the counter value will be the answer for the number of numbers in the specified range.
Below is a Python implementation of the above approach
# Python program for counting
# number of numbers in the given range
# use of bypass code and double line p>
count (list1 , l, r):
# move to list 1
# check status
x & gt;
x & lt;
# driver code
count (list1, l, r)
Single line approach:
We can write one line to traverse and checks the condition together:
x for x in list1 if l & lt; = x & lt; = r
Return value (tr ue) the condition check is stored in the list and at the end the length of the list returns the response.
Below is the Python implementation of the above approach