Created
February 26, 2021 21:19
-
-
Save pamelafox/5a0ea6cf2b2bd391d1864e0369ac0f88 to your computer and use it in GitHub Desktop.
Comparing with dis
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 dis | |
def for_version(): | |
y = 0 | |
for x in [1, 2, 3]: | |
y += x * 2 | |
def iter_version(): | |
_gen_ = iter([1, 2, 3]) | |
y = 0 | |
try: | |
while True: | |
y += next(_gen_) * 2 | |
except StopIteration: | |
pass | |
dis.dis(for_version) | |
dis.dis(iter_version) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment