Given a list, print all the values in a list that are greater than the given value

Examples:
Input : list = [10, 20, 30, 40, 50]
given value = 20
Output : No
Input : list = [10, 20, 30, 40, 50]
given value = 5
Output : Yes
Method 1: Traversal of list
By traversing in the list, we can compare every element and check if all the elements in the given list are greater than the given value or not.
# python program to check if all # values in the list are greater # than val using traversal def check(list1, val): # traverse in the list for x in list1: # compare with all the values # with val if val>= x: return False return True # driver code list1 =[10, 20, 30, 40, 50, 60] val = 5if(check(list1, val)): print"Yes"else: print"No" val = 20 if(check(list1, val)): print"Yes"else: print"No" |
Output:
Yes No
Method 2: Using all() function:
Using all() function we can check if all values are greater 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.
# python program to check if all # values in the list are greater # than val using all() function def check(list1, val): return(all(x > val for x in list1)) # driver code list1 =[10, 20, 30, 40, 50, 60] val = 5if(check(list1, val)): print"Yes"else: print"No" val = 20 if (check(list1, val)): print"Yes"else: print"No" |
Output:
Yes No
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.
Recommended Posts:
- Smallest subarray of size greater than K with sum greater than a given value
- Length of longest subarray in which elements greater than K are more than elements not greater than K
- Python | Check if all the values in a list are less than a given value
- Python - Remove keys with Values Greater than K ( Including mixed values )
- Python | Number of values greater than K in list
- Python - Extract list with difference in extreme values greater than K
- Sum of all array elements less than X and greater than Y for Q queries
- Python - Test if common values are greater than K
- Python - Extract dictionaries with values sum greater than K
- Python - Test if Values Sum is Greater than Keys Sum in dictionary
- Counting values greater than equal to x after increments
- Count elements such that there are exactly X elements with values greater than or equal to X
- Count the values greater than X in the modified array
- Python - Assigning Key values to list elements from Value list Dictionary
- Sort a String in decreasing order of values associated after removal of values smaller than X
- Smallest subarray with sum greater than a given value
- Length of Smallest subarray in range 1 to N with sum greater than a given value
- Python | Records with Key's value greater than K
- Find the element before which all the elements are smaller than it, and after which all are greater
- Python - Assign values to Values List
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

