5

Say I have two lists, and I run the following command

>>> s = [1, 2, 3]
>>> t = [1, 2, 4]
>>> s > t
False
>>> s < t
True

But if I were to run the following command

>>> s = [1, 2, 3]
>>> t = [1, 1, 4]
>>> s > t
True
>>> s < t
False

Have to admit, I'm not too familiar with the PY3 codebase. What exactly is going on in the __lt__, __le__, __gt__, __ge__, __ne__, __eq__ methods?

user2357112
  • 260,549
  • 28
  • 431
  • 505
mortonjt
  • 650
  • 1
  • 5
  • 23

2 Answers2

6

The comparison is lexicographical. If you read the definition of that, you will understand everything.

Iterate the pairs of elements in order, and the first non-equal pair determines the winner of the ordering.

wim
  • 338,267
  • 99
  • 616
  • 750
1

It's comparing them naively, i.e. element by element. 4 > 3, but 2 > 1.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358