Skip to content

Instantly share code, notes, and snippets.

@amontalenti
Last active September 27, 2015 11:48
Show Gist options
  • Save amontalenti/1265238 to your computer and use it in GitHub Desktop.
Save amontalenti/1265238 to your computer and use it in GitHub Desktop.
strange Python sorting behavior
>>> a = [1, 2]
>>> b = (1, 2)
>>> a < b
True
>>> b > a
True
>>> b < a
False
>>> c = [
... (1, 2, 3),
... (2, 3, 4),
... (3, 4, 5)
... ]
>>> c
[(1, 2, 3), (2, 3, 4), (3, 4, 5)]
>>> sorted(c, reverse=True)
[(3, 4, 5), (2, 3, 4), (1, 2, 3)]
>>> c = [(1, 2, 3),
(2, 3, 4),
(3, 4, 5),
[1, 2, 3],
[2, 3, 4],
{'foo': True},
{'bar': False}]
>>> sorted(c, reverse=True)
[(3, 4, 5),
(2, 3, 4),
(1, 2, 3),
[2, 3, 4],
[1, 2, 3],
{'foo': True},
{'bar': False}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment