
def condition(champ):
    return champ%2==0

def select(table,listeNumeros):
    newT=dict()
    for clef in table:
        old=table[clef]
        newT[clef]=[old[i] for i in listeNumeros]
    return newT

def where(table,numeroChamp,condition):
    newT=dict()
    for clef in table:
        old=table[clef]
        if condition(old[numeroChamp]):
            newT[clef]=old[:]
    return newT
      
def groupBy_Count(table,listeNumeros,numeroChamp):
    newT=dict()
    nbChamps=len(listeNumeros)
    for clef in table:
        old=table[clef]
        id=old[numeroChamp] 
        newEnr=[old[i] for i in listeNumeros]
        if id in newT:
            for j in range(nbChamps):
                assert newEnr[j]==newT[id][j]
            newT[id][nbChamps]+=1
        else:
            newEnr.append(1)
            newT[id]=newEnr
    return newT
            
def produit(t1,t2):
    newT=dict()
    for k1 in t1:
        for k2 in t2:
            newT[(k1,k2)]=t1[k1]+t2[k2]
    return newT
            
def jointure(t1,t2,champ1,champ2):
    newT=dict()
    for k1 in t1:
        for k2 in t2:
            if t1[k1][champ1]==t2[k2][champ2]:
                newT[(k1,k2)]=t1[k1]+t2[k2]
    return newT
    
test=dict()
test[2]=[3,5,7,12]
test[4]=[3,5,9,12]
test[9]=[3,5,7,12]
test[12]=[3,5,7,4]
test[21]=[4,4,4,2]

print(groupBy_Count(test,[0,1],2))