Skip to content

Instantly share code, notes, and snippets.

@pamelafox
Created February 26, 2021 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pamelafox/5a0ea6cf2b2bd391d1864e0369ac0f88 to your computer and use it in GitHub Desktop.
Save pamelafox/5a0ea6cf2b2bd391d1864e0369ac0f88 to your computer and use it in GitHub Desktop.
Comparing with dis
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