Skip to content

Instantly share code, notes, and snippets.

@hfm
Last active January 1, 2016 01:09
Show Gist options
  • Select an option

  • Save hfm/8070667 to your computer and use it in GitHub Desktop.

Select an option

Save hfm/8070667 to your computer and use it in GitHub Desktop.
import dis
def foriter():
ilist = []
for i in range(3):
ilist.append(i)
return ilist
dis.dis(foriter)
print "-----------------------------------------------------------------------"
def listc():
ilist = [i for i in range(3)]
return ilist
dis.dis(listc)
5 0 BUILD_LIST 0
3 STORE_FAST 0 (ilist)
6 6 SETUP_LOOP 33 (to 42)
9 LOAD_GLOBAL 0 (range)
12 LOAD_CONST 1 (3)
15 CALL_FUNCTION 1
18 GET_ITER
>> 19 FOR_ITER 19 (to 41)
22 STORE_FAST 1 (i)
7 25 LOAD_FAST 0 (ilist)
28 LOAD_ATTR 1 (append)
31 LOAD_FAST 1 (i)
34 CALL_FUNCTION 1
37 POP_TOP
38 JUMP_ABSOLUTE 19
>> 41 POP_BLOCK
8 >> 42 LOAD_FAST 0 (ilist)
45 RETURN_VALUE
-----------------------------------------------------------------------
15 0 BUILD_LIST 0
3 LOAD_GLOBAL 0 (range)
6 LOAD_CONST 1 (3)
9 CALL_FUNCTION 1
12 GET_ITER
>> 13 FOR_ITER 12 (to 28)
16 STORE_FAST 0 (i)
19 LOAD_FAST 0 (i)
22 LIST_APPEND 2
25 JUMP_ABSOLUTE 13
>> 28 STORE_FAST 1 (ilist)
16 31 LOAD_FAST 1 (ilist)
34 RETURN_VALUE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment