Iterators and generators · 13 / 15 Exercise Easy

First element that matches

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, next returns None.
  • Show First: X, or None if there is none.
Input
3 8 1 12 5
6
Output
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