小编kon*_*nfi的帖子

Python set().issubset()没有按预期工作

我正在尝试set().issubset()用于比较序列.你可以想象,它没有像预期的那样工作;)提前:抱歉长代码blob.

class T(object):
  def __init__(self, value, attributes = None):
    self.value = value
    self.attributes = Attributes(attributes)

  def __eq__(self, other):
    if not isinstance(other, T):
      return False
    if self.value == other.value and self.attributes == other.attributes:
      return True
    else:
      return False

  def __ne__(self, other):
    if not isinstance(other, T):
      return True
    if self.value != other.value or self.attributes != other.attributes:
      return True
    else:
      return False

class Attributes(dict):
  def __init__(self, attributes):
    super(dict, self)
    self.update(attributes or dict())

  def __eq__(self, other):
    if self.items() == other.items():
      return True …
Run Code Online (Sandbox Code Playgroud)

python set python-2.7

5
推荐指数
1
解决办法
2538
查看次数

标签 统计

python ×1

python-2.7 ×1

set ×1