Problem 211328 · easy · Level 02 Linear Data Structures

Where the Image Is Bright

py-comprehensions · py-enumerate · grids

A greyscale image is a grid of brightness values: image[r][c] is the value in row r, column c. Rows may have different lengths (a cropped scan).

Write bright_cells(image, threshold) that returns the (row, col) positions of every value that is at least threshold, going row by row from the top and, within a row, from left to right.

Examples

Input:  image = [[0, 9, 3],
                 [7, 2, 8]], threshold = 7
Output: [(0, 1), (1, 0), (1, 2)]

Input:  image = [[5], [], [1, 6]], threshold = 6
Output: [(2, 1)]
Explanation: Row 1 is empty; in row 2 only the 6 at column 1 is bright enough.

Constraints

  • 0 <= len(image) <= 1000, each row has 0 to 1000 values
  • at most 10**6 values in total

Goals

  • Build a list with a comprehension that has two `for` clauses and a filter
  • Get row and column numbers together with the values from `enumerate`
  • Keep the natural row-by-row order of a grid
Starting Python…