no hash tools

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)]

原文地址:https://www.cnblogs.com/small-office/p/9338074.html