Type error Unhashable type:set

前端 未结 2 760
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条回答
  •  猫巷女王i
    2020-11-30 06:21

    The individual items that you put into a set can't be mutable, because if they changed, the effective hash would change and thus the ability to check for inclusion would break down.

    Instead, you need to put immutable objects into a set - e.g. frozensets.

    If you change the return statement from your enum method to...

    return [frozenset(i) for i in L]
    

    ...then it should work.

提交回复
热议问题