-1
def check(A,B,a,b):
    return A >= a and B >= b

A = [500, 500, 500]
a = [20, 0, 0]
B = [5, 5, 5, 5]
b = [0, 10, 0, 0]

print(check(A, B, a, b))

(result True)

I want result become False if only one in list A or B have small value than a or b. In this code B[1] < b[1] (5 >= 10) result I expect is False but is output True

Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91
Cha
  • 9
  • 2
  • Does this answer your question? [Comparing two lists using the greater than or less than operator](https://stackoverflow.com/questions/13052857/comparing-two-lists-using-the-greater-than-or-less-than-operator) – DarkKnight Sep 03 '22 at 10:15

1 Answers1

1

From official doc:

The comparison uses lexicographical ordering: first the first two items are compared, and if they differ this determines the outcome of the comparison; if they are equal, the next two items are compared, and so on, until either sequence is exhausted.


To get False in your example, you can use built-in all() to compare all values in arrays:

def check(A, B, a, b):
    return all(x >= y for x, y in zip(A, a)) and all(x >= y for x, y in zip(B, b))


A = [500, 500, 500]
a = [20, 0, 0]
B = [5, 5, 5, 5]
b = [0, 10, 0, 0]

print(check(A, B, a, b))

Prints:

False
Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91