# Python – Check if all the values in a list that are greater than a given value

## Python | Check if all the values in a list that are greater than a given value

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 ``=` `5` `if``(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 ``=` `5` `if``(check(list1, val)):` `    ``print``"Yes"` `else``:` `    ``print``"No"` ` ` `val ``=` `20` `if` `(check(list1, val)):` `    ``print``"Yes"` `else``:` `    ``print``"No"`

Output:

```Yes
No```

Last Updated on March 1, 2022 by admin

## Python – Display images with PyGamePython – Display images with PyGame

Python | Display images with PyGame Pygame is a cross-platform set of Python modules designed for

## Matplotlib.pyplot.savefig() in PythonMatplotlib.pyplot.savefig() in Python

Matplotlib.pyplot.savefig() in Python Matplotlib is highly useful visualization library in Python. It is a multi-platform data

## click() element method – Selenium Pythonclick() element method – Selenium Python

click() element method – Selenium Python Selenium’s Python Module is built to perform automated testing

## send_keys() element method – Selenium Pythonsend_keys() element method – Selenium Python

send_keys() element method – Selenium Python Selenium’s Python Module is built to perform automated testing

## close() and quit() method in Selenium Pythonclose() and quit() method in Selenium Python

How to use close() and quit() method in Selenium Python ? While doing stuff with

## User-defined Exceptions in Python with ExamplesUser-defined Exceptions in Python with Examples

User-defined Exceptions in Python with Examples Python throws errors and exceptions when there is a

## Matplotlib.pyplot.xlim() in PythonMatplotlib.pyplot.xlim() in Python

Matplotlib.pyplot.xlim() in Python There are various plots which can be used in Pyplot are Line

## Python – Check if list is sorted or notPython – Check if list is sorted or not

Python | Check if list is sorted or not The sorted operation of list is