0

// It is just changing values of first row and not the whole table ? can someone tell me how to run loop in whole table

def remove_outliers(table):
     mx = max(map(max, table))
     mn = min(map(min, table))
     avg = (mx + mn) / 2
     for row in table:
         row[:] = [avg if x in (mx, mn) else x for x in row]
         return table


2 Answers2

0

I think your return table is intended wrong. It will return after the first row is processed. Try this:

def remove_outliers(table):
    mx = max(map(max, table))
    mn = min(map(min, table))
    avg = (mx + mn) / 2
    for row in table:
        row[:] = [avg if x in (mx, mn) else x for x in row]
    return table

Lydia van Dyke
  • 2,466
  • 3
  • 13
  • 25
0

The return statement is in the wrong place. The function will exit in the first iteration itself. Un-indent return statement out of for loop. Then it will exit after the complete iteration

for row in table:
    row[:] = [avg if x in (mx, mn) else x for x in row]
return table
Aroo
  • 55
  • 1
  • 10