fork download
  1. import dis
  2.  
  3. ge=(x*x for x in [1,2,3])
  4.  
  5. print('Genexp:')
  6. dis.dis(ge)
  7.  
  8. def genfunc(outer_iterable):
  9. for x in outer_iterable:
  10. yield x*x
  11.  
  12. ge = genfunc([1, 2, 3])
  13.  
  14. print()
  15. print('Generator function:')
  16. dis.dis(ge)
Success #stdin #stdout 0.04s 9560KB
stdin
Standard input is empty
stdout
Genexp:
  3           0 LOAD_FAST                0 (.0)
        >>    3 FOR_ITER                15 (to 21)
              6 STORE_FAST               1 (x)
              9 LOAD_FAST                1 (x)
             12 LOAD_FAST                1 (x)
             15 BINARY_MULTIPLY
             16 YIELD_VALUE
             17 POP_TOP
             18 JUMP_ABSOLUTE            3
        >>   21 LOAD_CONST               0 (None)
             24 RETURN_VALUE

Generator function:
  9           0 SETUP_LOOP              23 (to 26)
              3 LOAD_FAST                0 (outer_iterable)
              6 GET_ITER
        >>    7 FOR_ITER                15 (to 25)
             10 STORE_FAST               1 (x)

 10          13 LOAD_FAST                1 (x)
             16 LOAD_FAST                1 (x)
             19 BINARY_MULTIPLY
             20 YIELD_VALUE
             21 POP_TOP
             22 JUMP_ABSOLUTE            7
        >>   25 POP_BLOCK
        >>   26 LOAD_CONST               0 (None)
             29 RETURN_VALUE