- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
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")
The list is : [5, 6, 4, 7, 8, 13, 15] All the elements are not in the min/max range
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.
- Python – Combine list with other list elements
- Python – Test if list is Palindrome
- Python – Extract range of Consecutive similar elements ranges from string list
- Find Min-Max in heterogeneous list in Python
- Python – Check if elements index are equal for list elements
- Python – Test for all Even elements in the List for the given Range
- Python – All replacement combination from other list
- Python – Test for Word construction from character list
- Python – Test if tuple list has a single element
- List Methods in Python - in, not in, len(), min(), max()
- Python – Extract elements from Ranges in List
- Python – Check if elements in a specific index are equal for list elements
- Python – Maximum of K element in other list
- Assign range of elements to List in Python
- Python – Random range in a List