'How does Python determine which coordinates is greater?
Say, I have two lists each containing just a pair of coordinates:
list1 = [2,1]
list2 = [1,2]
list3 = [2,3]
Why does list1 > list2 evaluate to True
but list2 > list3 evaluate to false?
Solution 1:[1]
It compares element by element until it finds two different values at which point it returns either True or False depending on which list contains the larger value. It is equivalent to the following:
def compare(a, b):
# Equivalent to a > b
for i, j in zip(a, b):
if i > j:
return True
elif i < j:
return False
return False
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nin17 |
