Skip to content

Instantly share code, notes, and snippets.

@mahmoud
Last active December 15, 2015 00:39
Show Gist options
  • Save mahmoud/5174827 to your computer and use it in GitHub Desktop.
Save mahmoud/5174827 to your computer and use it in GitHub Desktop.
the strange work of lists and tuples.
"""
comparing tuples to tuples is faster than comparing lists to lists,
but more interestingly, comparing a tuple to a list is apparently
faster than lists to lists.
"""
$ python -m timeit "[1, 1] < [1, 2]"
10000000 loops, best of 3: 0.186 usec per loop
$ python -m timeit "[1, 1] < (1, 2)"
10000000 loops, best of 3: 0.129 usec per loop
$ python -m timeit "(1, 1) < (1, 2)"
10000000 loops, best of 3: 0.0649 usec per loop
# and here is why:
>>> (1, 1) > (1, 2)
False
>>> (1, 1) > [1, 2]
True
>>> [1, 1] > [1, 2]
False
"""
I don't even know.
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment