Frame Versus Centre

Data with PythonMedium+10 XP+10

Frame Versus Centre

A camera app checks whether a photo is darker around its edges than in the middle. The photo is a grid of brightness values: one list per row, all rows the same length.

  • The frame is every value in the first row, the last row, the first column and the last column. Each value counts once, even the corners.
  • The inside is every other value.

Task: write frame_and_inside(image) and return a dict:

  • "frame" — the average of the frame values,
  • "inside" — the average of the inside values.

Round both to 2 decimal places. The photo always has at least 3 rows and at least 3 columns, so there is always some inside.

Examples

image = [[10, 10, 10], [10, 90, 10], [10, 10, 10]]
returns {'frame': 10.0, 'inside': 90.0}
image = [[3, 1, 4, 1], [5, 9, 2, 6], [5, 3, 5, 8], [9, 7, 9, 3]]
returns {'frame': 5.08, 'inside': 4.75}

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run