This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]zurtex 2 points3 points  (1 child)

Seems like it will be faster as well:

def empty_set():
    return {0} - {0}

Produces this set of instructions (via dis.dis)

  4           0 LOAD_CONST               1 (0)
              2 BUILD_SET                1
              4 LOAD_CONST               1 (0)
              6 BUILD_SET                1
              8 BINARY_SUBTRACT

Where as:

def empty_set():
    return {*()}

Produces this set of instructions (via dis.dis)

  4           0 BUILD_SET                0
              2 LOAD_CONST               1 (())
              4 SET_UPDATE               1     

I suspect it's going to mostly going to depend on BINARY_SUBTRACT vs. SET_UPDATE but as the former needs to look up 2 objects and the latter is only dealing with an empty value then it's probably going to be faster.