Given a list, write a Python program to check if all the values in a list are less than the given value.
Input : list = [11, 22, 33, 44, 55] value = 22 Output : No Input : list = [11, 22, 33, 44, 55] value = 65 Output : Yes
Method #1: Traversing the list
Compare each element by iterating through the list and check if all the elements in the given list are less than the given value or not.
Method #2: Using
all() function we can check if all values are less than any given value in a single line. It returns true if the given condition inside the all() function is true for all values, else it returns false.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course