This file contains hidden or 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
| Python 2.7.2+ (default, Jun 29 2011, 00:07:42) | |
| [GCC 4.6.1 20110616 (prerelease)] on linux2 | |
| Type "help", "copyright", "credits" or "license" for more information. | |
| >>> class A(object): | |
| ... pass | |
| ... | |
| >>> A.__doc__ = "doc" | |
| Traceback (most recent call last): | |
| File "<stdin>", line 1, in <module> | |
| AttributeError: attribute '__doc__' of 'type' objects is not writable |
This file contains hidden or 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
| >>> timeit.repeat("a = deque()\nfor i in xrange(10000): a.append(i)\nfor x in a: x", | |
| ... "from collections import deque", number=1000) | |
| [1.4415068626403809, 1.4344120025634766, 1.4339849948883057] | |
| >>> timeit.repeat("a = []\nfor i in xrange(10000): a.append(i)\nfor x in a: x", number=1000) | |
| [1.3635458946228027, 1.3510761260986328, 1.3518819808959961] |
This file contains hidden or 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
| >>> timeit.repeat("for i in xrange(1000): a.append(i)", | |
| ... "from collections import deque; a = deque()", number=10000) | |
| [1.139456033706665, 1.1287789344787598, 1.129647970199585] | |
| >>> timeit.repeat("for i in xrange(1000): a.append(i)", "a = []", number=10000) | |
| [1.1056618690490723, 1.0919761657714844, 1.0903148651123047] |
This file contains hidden or 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
| In [1]: %timeit sum([(0, 0)] * 1000, ()) | |
| 100 loops, best of 3: 5.01 ms per loop | |
| In [2]: %timeit sum([(0, 0)] * 10000, ()) | |
| 1 loops, best of 3: 490 ms per loop | |
| In [3]: %timeit sum([(0, 0)] * 100000, ()) | |
| 1 loops, best of 3: 61.9 s per loop |
This file contains hidden or 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
| def compose(*funcs): | |
| def comp(x): | |
| for f in reversed(funcs): | |
| x = f(x) | |
| return x | |
| return comp |
This file contains hidden or 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
| In [1]: a = 256 | |
| In [2]: b = 256 | |
| In [3]: a is b | |
| Out[3]: True | |
| In [4]: a = 257 | |
| In [5]: b = 257 |
This file contains hidden or 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
| import timeit | |
| a = range(10000) | |
| da = set(a) | |
| def list_first(): | |
| return 0 in a | |
| def set_first(): | |
| return 0 in da |
NewerOlder