Skip to content

Instantly share code, notes, and snippets.

@fcofdez
Created August 21, 2015 19:57
Show Gist options
  • Save fcofdez/f52a8303e5daf4a86f68 to your computer and use it in GitHub Desktop.
Save fcofdez/f52a8303e5daf4a86f68 to your computer and use it in GitHub Desktop.
In [14]: dis(x)
2 0 BUILD_LIST 0
3 LOAD_GLOBAL 0 (range)
6 LOAD_CONST 1 (10)
9 CALL_FUNCTION 1
12 GET_ITER
>> 13 FOR_ITER 16 (to 32)
16 STORE_FAST 0 (x)
19 LOAD_FAST 0 (x)
22 LOAD_CONST 2 (1)
25 BINARY_ADD
26 LIST_APPEND 2
29 JUMP_ABSOLUTE 13
>> 32 RETURN_VALUE
def x():
return [x + 1 for x in range(10)]
def y():
a = []
for x in range(10):
a.append(x+1)
return a
In [17]: dis(y)
2 0 BUILD_LIST 0
3 STORE_FAST 0 (a)
3 6 SETUP_LOOP 37 (to 46)
9 LOAD_GLOBAL 0 (range)
12 LOAD_CONST 1 (10)
15 CALL_FUNCTION 1
18 GET_ITER
>> 19 FOR_ITER 23 (to 45)
22 STORE_FAST 1 (x)
4 25 LOAD_FAST 0 (a)
28 LOAD_ATTR 1 (append)
31 LOAD_FAST 1 (x)
34 LOAD_CONST 2 (1)
37 BINARY_ADD
38 CALL_FUNCTION 1
41 POP_TOP
42 JUMP_ABSOLUTE 19
>> 45 POP_BLOCK
5 >> 46 LOAD_FAST 0 (a)
49 RETURN_VALUE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment