2
Hello I need to compare 2 values of 2 arrays, but I’m not if succeeding:
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 equal I will use them; but it is not working. What am I doing wrong? I’ve had this problem for a long time and I can’t solve it in any way!
I ran your code and when the
Cod
of the two arrays is11518
he printsExemplo1
. It’s not right that? Running on the Ideone– Math
Idem here - your approach may not be the best possible, but it is technically correct. What error did you get? Is the data you are using the same? Codes are always strings like here, or in your data are sometimes integer and sometimes string?
– jsbueno
My data is strings but I need to keep turning one by one to int, is there any way to do this with everyone? (Except the product name) And as for the approach, what would be the best approach to be taken?
– mrlucasrib