import copy

from databaseConn import *
def listCross(a,b):
    '''
    :param a:list1
    :param b:list2
    :return:list交叉排序
    '''
    #print(a,b)
    temp=[]
    flen=len(b) if len(a)>len(b) else len(a)
    print(flen)
    for i in range(flen):
        temp.append(a.pop(0))
        temp.append(b.pop(0))
    temp+=a
    temp+=b
    return temp

def removeRepeat(a):
    '''
    :param a:list
    :return:按顺序去掉重复词
    '''
    temp=list(set(a))
    temp.sort(key=a.index)
    return temp

def subtraction(a,b):
    if a and  b:
        return list(set(a).difference(set(b)))
    return b if b else a


def mergelist(a):
    '''
    :param a:list
    :return: 嵌套list合并成一个
    '''
    t=itertools.chain.from_iterable(a)
    return list(t)


def listGroup(tt,size=3):
    '''
    :param tt:
    :param size:没用，预留值
    :return: list分组，按照递增分组
    '''
    temp=[]
    i=1
    while True:
        temp.append(tt[:i])
        [tt.remove(ii) for ii in tt[:i]]
        i+=1
        if not tt:
            break
    return temp

def listSubgroup(tt,size=6):
    temp=[]
    for i in range(0,len(tt),size):
        print(tt[i:i+size])
        temp.append(tt[i:i+size])
    return temp


if __name__ == '__main__':
    a=[1,2,4,3,5,6,7,8]
    #print(listGroup(a))

    #a=[[1,2],[2,3]]
    #print(mergelist(a))

    print(listSubgroup(a,6))
