Last active
December 15, 2015 00:39
-
-
Save mahmoud/5174827 to your computer and use it in GitHub Desktop.
the strange work of lists and tuples.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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