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

posted @ 2018-07-19 20:03  Small_office  阅读(122)  评论(0编辑  收藏  举报