0
scores = [[100,90,98,88,65],[50,45,99,85,77]]

for i in range(len(scores)):
    for j in range(len(scores[0])):
        if scores[i][j] != min(scores[i]) or scores[i][j] != max(scores[i]):
            print (scores[i][j])
Result
100
90
98
88
65
50
45
99
85
77

I want to delete 100(the max value of the first row) and 45(the min value of the second row). But it doesn't work I think there's a problem with 'or' function. but I don't know what it is.

Chicori
  • 11
  • 1
  • 3
    What you need is `and`, not `or`. The value should NOT be equal to the max, AND it should NOT be equal to the min. – Selcuk Aug 13 '21 at 06:24
  • You need to use additional condition as `i==0` with maximum and `i==1` with minimum – ThePyGuy Aug 13 '21 at 06:26
  • `or` is an operator, not a function. That said, the problem is simply thinking more clearly about the logic. You have two conditions that you're checking: `scores[i][j] != min(scores[i])`, and `scores[i][j] != max(scores[i])`. Do you need either of them to be true? Both of them to be true? Something else? Why? – Karl Knechtel Aug 13 '21 at 06:26
  • Oh my god I get it Thank you !!!! – Chicori Aug 13 '21 at 06:27
  • 1
    Don't use range(len(...)). That is just confusing you more. Just iterate directly on list and use enumerate if u need a counter. – sureshvv Aug 13 '21 at 06:28
  • @KarlKnechtel While I agree with the duplicate, it's a partial one as there are other issues with the code that can't be simply fixed by understanding De Morgan's rules. – Selcuk Aug 13 '21 at 06:31
  • You have a gold badge for [python] too, so please feel free to add/edit the duplicates. I assumed the swap of `or` for `and` resulted from a failure to apply those rules properly, but there are other possible reasons. – Karl Knechtel Aug 13 '21 at 06:38
  • I'd try `[x for x in scores[0] if x != max(scores[0])] + [y for y in scores[1] if y != min(scores[1])] ` and it will produce `[90, 98, 88, 65, 50, 99, 85, 77]` – Dmitry Grekov Aug 13 '21 at 06:45

1 Answers1

0

You also need to check for the value of i i.e. row You want to compare against maximum for i=0 and minimum against i=1, and you need to combine these conditions by and operator, then or operator.

scores = [[100,90,98,88,65],[50,45,99,85,77]]
for i in range(len(scores)):
    for j in range(len(scores[0])):
        if (i==1 and scores[i][j] != min(scores[i])) or (i==0 and scores[i][j] != max(scores[i])):
            print (scores[i][j])
            
90
98
88
65
50
99
85
77
ThePyGuy
  • 17,779
  • 5
  • 18
  • 45