Type error Unhashable type:set

前端 未结 2 756
Happy的楠姐
Happy的楠姐 2020-11-30 05:49

The below code has an error in function U=set(p.enum()) which a type error of unhashable type : \'set\' actually if you can see the class method enum am returning \'L\' whic

2条回答
  •  借酒劲吻你
    2020-11-30 06:33

    This error is raised because a set can only contain immutable types. Or sets are mutable. However there is the frozenset type :

    In [4]: a, b = {1,2,3}, {2,3,4}
    
    In [5]: set([a,b])
    ---------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
     in ()
    ----> 1 set([a,b])
    
    TypeError: unhashable type: 'set'
    
    In [6]: a, b = frozenset({1,2,3}), frozenset({2,3,4})
    
    In [7]: set([a,b])
    Out[7]: {frozenset({1, 2, 3}), frozenset({2, 3, 4})}
    

提交回复
热议问题