Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function findMaxDiff() that takes a two-dimensional list of positive int

ID: 3757652 • Letter: W

Question

Write a function findMaxDiff() that takes a two-dimensional list of positive integers as a parameter. It prints the index of the row with the maximum difference between elements as well as the value of the maximum difference in that row. The maximum difference between elements in a row is defined to be the difference between the largest and smallest elements in the row. The function must not modify the list passed as a parameter. You may assume that each sublist in the parameter has at least one item in it. If there are multiple sublists that all achieve the maximum difference, the first sublist should be reported as the one with the maximum difference. The following shows several sample runs of the function:

Explanation / Answer

def findMaxDiff(mylist):
for i in range(len(mylist)):
if i == 0 :
maxdiff = max(mylist[i])-min(mylist[i]);
maxindex = i;
else :
if (max(mylist[i])-min(mylist[i]) > maxdiff) :
maxdiff = max(mylist[i])-min(mylist[i]);
maxindex = i;
print "The maximum difference of",maxdiff,"is found in row",maxindex,"."

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote