w3resource

Python: Find all the values in a list are greater than a specified number

Python List: Exercise - 67 with Solution

Find Values Greater Than Specified Number

Write a Python program to find all the values in a list that are greater than a specified number.

Visual Presentation:

Python List: Find all the values in a list are greater than a specified number.
Python List: Find all the values in a list are greater than a specified number.

Sample Solution:

Python Code:

# Define two lists, 'list1' and 'list2', containing integers
list1 = [220, 330, 500]
list2 = [12, 17, 21]

# Check if all elements in 'list1' are greater than or equal to 200 using a generator expression and the 'all' function
# The 'all' function returns 'True' if all elements meet the condition, otherwise 'False'
print(all(x >= 200 for x in list1))

# Check if all elements in 'list2' are greater than or equal to 25 using a generator expression and the 'all' function
# The 'all' function returns 'True' if all elements meet the condition, otherwise 'False'
print(all(x >= 25 for x in list2))

Sample Output:

True                                                                                                          
False

Flowchart:

Flowchart: Find all the values in a list are greater than a specified number

Python Code Editor:

Previous: Write a Python program to find the list in a list of lists whose sum of elements is the highest.
Next: Write a Python program to extend a list without append.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/python-exercises/list/python-data-type-list-exercise-67.php