Compare values of two arrays

1

Hello, I need to compare 2 values of 2 arrays, but I'm not if getting:

plan = [{'Cod': '11518', 'qtdPallet': '176', 'qtdLastro': '22', 'qtdCx': '12', 'Prod': 'Exemplo1', 'FC': '1'}, {'Cod': '972', 'qtdPallet': '72', 'qtdLastro': '9', 'qtdCx': '24', 'Prod': 'Exemplo2', 'FC': '2'}]
dados = [{'qtdCx': '133', 'qtdUn': '00', 'Cod': '11518'}, {'qtdCx': '345', 'qtdUn': '5', 'Cod': '13'}, {'qtdCx': '234', 'qtdUn': '03', 'Cod': '13205'}, {'qtdCx': '3545', 'qtdUn': '09', 'Cod': '16'}, {'qtdCx': '1884', 'qtdUn': '03', 'Cod': '978'}]

def calcula():
    for plax in plan:
        for dad in dados:
            if dad['Cod'] == plax['Cod']:
                print(plax["Prod"])

calcula()

I compare the codes of each and if they are the same I will use them; but it's not working. What am I doing wrong? I've had this problem for a long time and I can not solve it in any way!

    
asked by anonymous 16.06.2016 / 15:29

1 answer

1
def converte(dados): # retorna uma nova lista de dict  para DADOS, com os item para INT
    novo = []
    for i in dados:
        for j in i:
            i[j] = int(i[j])
            novo.append(i)
    if len(novo)%2 == 0:
        return novo[::2]
    else:
        return novo[::3]


def verifica(plan, dados): # mesma coisa da sua funcao calcula faz a checagem do Cod com todas as ocorrencias porem retorna a String de Prod
    for i in range(len(plan)):
        for j in range(len(dados)):
            if plan[i]['Cod'] in dados[j]['Cod']:
                return plan[i]['Prod']
            else:
                pass
    
20.06.2016 / 12:08