Objective
Create a Python program that finds the first element that meets a condition with a generator expression and next(), without building any list.
Instructions
- Read a line with integers separated by spaces and, on the next line, an integer
threshold. - Use
next((x for x in numbers if x > threshold), None)to get the first number greater than the threshold; if there is none,nextreturnsNone. - Show
First: X, orNoneif there is none.
3 8 1 12 5
6
First: 8
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise