You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.1 KiB

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2023/4/5 11:26
# @Author : old tom
# @File : fu_collection.py
# @Project : futool-db
# @Desc : 集合类工具
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)))