Question: Can someone solve these for me using only len(), range(), append(), and del keyword when needed as the directions state? No list comprehension, slicing, or

Can someone solve these for me using only len(), range(), append(), and del keyword when needed as the directions state? No list comprehension, slicing, or importing modules. No chr or index(i) functions.

def reduce_matrix(mat)

Reduces the size of matrix mat in half, in both dimensions, by merging adjacent elements

The new values of the matrix are the average of the respective merged elements

Return value is None. Variable mat is directly modified in memory

mat is a nested list (e.g. [[1,2,3,4], [5,6,7,8]] and is guaranteed to be non-empty and have a rectangular shape. Both dimensions are even numbers

Youre not allowed to use slicing, or import modules, or use the list comprehension syntax

The only functions youre allowed to use are: len() , range() and the del keyword

Examples:

reduce_matrix([[1,2],[3,4]]) '[[2.5]]' reduce_matrix([[1,2,3,4],[5,6,7,8],[9,8,7,6],[5,4,3,2]]) '[[3.5,5.5],[6.5,4.5]]'

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!