
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python – Test if elements of list are in Min/Max range from other list
When it is required to test if the elements are in the min/max range, the list elements are iterated over, and are checked to see if it is equal to ‘max’ value.
Example
Below is a demonstration of the same
my_list = [5, 6, 4, 7, 8, 13, 15] print("The list is : ") print(my_list) range_list = [4, 7, 10, 6] my_result = True for elem in range_list: if elem!= max(my_list): my_result = False break if(elem == True): print("All the elements are in the min/max range") else: print("All the elements are not in the min/max range")
Output
The list is : [5, 6, 4, 7, 8, 13, 15] All the elements are not in the min/max range
Explanation
A list is defined and is displayed on the console.
Another list of integers is defined.
A variable is assigned to ‘True’.
The values in the list of integers are iterated over.
If the maximum of the elements in the original list is not equal to any element in the list of integers, the result variable is set to ‘False’.
It breaks out of the loop.
In the end, it is checked to see if the value is ‘True’ or not.
Depending on this, the relevant result is displayed on the console.
- Related Articles
- Find Min-Max in heterogeneous list in Python
- List Methods in Python - in, not in, len(), min(), max()
- Python – Combine list with other list elements
- Python – Test for all Even elements in the List for the given Range
- Assign range of elements to List in Python
- Python – Extract range of Consecutive similar elements ranges from string list
- Python – Test if list is Palindrome
- Remove a range of elements from the List in C#
- Python prorgam to remove duplicate elements index from other list
- Python Program to Test if string contains element from list
- Min-Max Range Queries in Array in C++
- Python – Check if elements index are equal for list elements
- Python - Check if all elements in a List are same
- Python - Check if all elements in a list are identical
- Check if elements of Linked List are present in pair in Python

Advertisements