#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2023/4/5 11:26 # @Author : old tom # @File : fu_collection.py # @Project : futool-db # @Desc : 集合类工具 import hashlib def split_coll(data: [], part_size=5): """ 分割集合 :param data: :param part_size: :return: """ rt = [] if len(data) <= part_size: rt.append(data) else: rt.append(data[0:part_size]) for j, d in enumerate(data): if j > 0 and j % part_size == 0: rt.append(data[j:j + part_size]) return rt def is_not_empty(coll: list) -> bool: """ 集合不为空 :param coll: :return: """ return coll is not None and len(coll) > 0 def list_symmetric_diff(coll_1: list, coll_2: list) -> list: """ 对称差集 :param coll_1: :param coll_2: :return: """ return list(set(coll_1).symmetric_difference(set(coll_2))) def list_diff(coll_1: list, coll_2: list) -> list: """ 差集 coll_1中有而coll_2中没有 :param coll_1: :param coll_2: :return: """ return list(set(coll_1).difference(set(coll_2))) def list_intersection(coll_1: list, coll_2: list) -> list: """ 求交集 """ return list(set(coll_1).intersection(set(coll_2))) def list_2_md5(coll: list) -> str: """ 合并列表内容 :param coll: :return: """ md5 = hashlib.md5() content = '' for e in coll: content += str(e) md5.update(content.encode(encoding='utf-8')) return md5.hexdigest()