import itertools


class Set(list):
    def __init__(self, params):
        super(Set, self).__init__()
        self.extend(reduce(lambda x, y: x if y in x else x + [y], [[], ] + params))

def __eq__(self, others):
    if len(self) != len(others):
        return False
    for param in self:
        if param not in others:
            return False
    return True


def union(*args):
    return Set(list(itertools.chain(*args)))


def intersection(*args):
    return reduce(lambda x, y: [z for z in union(x, y) if z in x and z in y], list(args))


def difference(*args):
    return [z for z in union(*args) if list(itertools.chain(*args)).count(z) == 1]


def all_difference(*args):
    return [z for z in union(*args) if z not in intersection(*args)]

相关文章:

  • 2021-07-15
  • 2021-05-01
  • 2021-09-06
  • 2021-09-22
  • 2021-08-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-20
  • 2022-12-23
  • 2021-12-19
  • 2022-12-23
  • 2021-08-26
  • 2022-12-23
  • 2021-12-05
相关资源
相似解决方案