Untitled

 avatar
unknown
python
20 days ago
1.3 kB
13
Indexable
def EsposizioneMaxCliente(T1):
   totali = {}
   
   for riga in T1:
       codice_cliente = riga[1]  
       importo = riga[2]         
       
       if codice_cliente in totali:
           totali[codice_cliente] = totali[codice_cliente] + importo
       else:
           totali[codice_cliente] = importo
   
   max_cliente = None
   max_totale = 0
   
   for cliente, totale in totali.items():
       if totale > max_totale:
           max_cliente = cliente
           max_totale = totale
           
   return [max_cliente, max_totale]

def ReportFlussiMonetari(T1, T2):
    risultato = []
    for riga_t1 in T1:
        cod_cliente = riga_t1[1]
        cod_ordine = riga_t1[0]
        importo_t1 = riga_t1[2]
        
        somma_t2 = 0
        for riga_t2 in T2:
            if riga_t2[4] == cod_ordine:
                somma_t2 = somma_t2 + riga_t2[3]
        
        differenza = somma_t2 - importo_t1
        risultato.append([cod_cliente, differenza])
        
    return risultato
 
   
T1 = [
    [25, "A16", 357, "02/04/24"],
    [13, "A17", 150, "08/01/24"],
    [26, "A16", 280, "23/06/22"]
]



T2 = [
    ["P1", "Carne", "24/01/24", 300, 25],
    ["P22", "Verdura", "13/05/22", 17, 13],
    ["P22", "Verdura", "04/10/23", 79, 13],
    ["P2", "Carne", "30/11/23", 57, 25]
]

print(ReportFlussiMonetari(T1,T2))
Leave a Comment