fork download
  1. def f1(seq):
  2. seen = set()
  3. return [ x for x in seq if x not in seen and not seen.add(x)]
  4.  
  5. def f7(seq):
  6. seen = set()
  7. seen_add = seen.add
  8. return [ x for x in seq if x not in seen and not seen_add(x)]
  9.  
  10. import dis
  11. print "f1"
  12. dis.dis(f1)
  13.  
  14. print "f7"
  15. dis.dis(f7)
Success #stdin #stdout 0.09s 8880KB
stdin
Standard input is empty
stdout
f1
  2           0 LOAD_GLOBAL              0 (set)
              3 CALL_FUNCTION            0
              6 STORE_FAST               1 (seen)

  3           9 BUILD_LIST               0
             12 LOAD_FAST                0 (seq)
             15 GET_ITER            
        >>   16 FOR_ITER                40 (to 59)
             19 STORE_FAST               2 (x)
             22 LOAD_FAST                2 (x)
             25 LOAD_FAST                1 (seen)
             28 COMPARE_OP               7 (not in)
             31 POP_JUMP_IF_FALSE       16
             34 LOAD_FAST                1 (seen)
             37 LOAD_ATTR                1 (add)
             40 LOAD_FAST                2 (x)
             43 CALL_FUNCTION            1
             46 UNARY_NOT           
             47 POP_JUMP_IF_FALSE       16
             50 LOAD_FAST                2 (x)
             53 LIST_APPEND              2
             56 JUMP_ABSOLUTE           16
        >>   59 RETURN_VALUE        
f7
  6           0 LOAD_GLOBAL              0 (set)
              3 CALL_FUNCTION            0
              6 STORE_FAST               1 (seen)

  7           9 LOAD_FAST                1 (seen)
             12 LOAD_ATTR                1 (add)
             15 STORE_FAST               2 (seen_add)

  8          18 BUILD_LIST               0
             21 LOAD_FAST                0 (seq)
             24 GET_ITER            
        >>   25 FOR_ITER                37 (to 65)
             28 STORE_FAST               3 (x)
             31 LOAD_FAST                3 (x)
             34 LOAD_FAST                1 (seen)
             37 COMPARE_OP               7 (not in)
             40 POP_JUMP_IF_FALSE       25
             43 LOAD_FAST                2 (seen_add)
             46 LOAD_FAST                3 (x)
             49 CALL_FUNCTION            1
             52 UNARY_NOT           
             53 POP_JUMP_IF_FALSE       25
             56 LOAD_FAST                3 (x)
             59 LIST_APPEND              2
             62 JUMP_ABSOLUTE           25
        >>   65 RETURN_VALUE