Set literal gives different result from set function call

后端 未结 2 1377
情深已故
情深已故 2021-02-02 05:52

Why does the set function call wipe out the dupes, but parsing a set literal does not?

>>> x = Decimal(\'0\')
>>> y = complex(0,0)         


        
2条回答
  •  不知归路
    2021-02-02 06:08

    It's all down to the order in which the set is constructed, combined with the bug you discovered with your other question. It appears that the literal is constructed in the opposite order to conversion from a list.

    >>> {0, x, y}
    set([0j, Decimal('0')])
    >>> {y, x, 0}
    set([0])
    

提交回复
热议问题