M
M
MaratGan2020-05-11 16:02:09
Python
MaratGan, 2020-05-11 16:02:09

How to display the value of another key from an array by the value of a key?

Good afternoon!

Tell me, please, I know the value of the "part_number" key, I need to derive the value from "part_code". I want to get the following result:

If part_number = 1, then part_code = 8E0505312AF

spoiler

{"parts":{"parts":[{"standart":{"part_number":"(1)","part_code":"8E0505312AF","part_name":"P\u044b\u0447\u0430\u0433 \u043f\u043e\u0434\u0432\u0435\u0441\u043a\u0438","part_quantity":1,"type":"part","node_link":"no"},"add":{"additional":""}},{"standart":{"part_number":"(1)","part_code":"8E0505311AF","part_name":"P\u044b\u0447\u0430\u0433 \u043f\u043e\u0434\u0432\u0435\u0441\u043a\u0438","part_quantity":1,"type":"part","node_link":"no"},"add":{"additional":""}},{"standart":{"part_number":"2","part_code":"WHT001675","part_name":"\u0428\u0430\u0439\u0431\u0430, \u044d\u043a\u0441\u0446\u0435\u043d\u0442\u0440\u0438\u043a\u043e\u0432\u0430\u044f","part_quantity":1,"type":"part","node_link":"no"},"add":{"additional":"31X3"}},{"standart":{"part_number":"(3)","part_code":"WHT001679","part_name":"\u042d\u043a\u0441\u0446\u0435\u043d\u0442\u0440\u0438\u043a\u043e\u0432\u044b\u0439 \u0431\u043e\u043b\u0442","part_quantity":"-","type":"part","node_link":"no"},"add":{"additional":"M12X110"}},{"standart":{"part_number":"4A","part_code":"N 91035802","part_name":"\u0417\u0430\u043f\u0440\u0435\u0441\u0441\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0433\u0430\u0439\u043a\u0430 C\u043c\u043e\u0442\u0440\u0438 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e \u0440\u0435\u043c\u043e\u043d\u0442\u0443","part_quantity":2,"type":"part","node_link":"no"},"add":{"additional":"M12X1,5-3"}},{"standart":{"part_number":"4","part_code":"N 90635001","part_name":"\u0413\u0430\u0439\u043a\u0430 \u0448\u0435\u0441\u0442\u0438\u0433\u0440\u0430\u043d\u043d\u0430\u044f \u0441\u0430\u043c\u043e\u043a\u043e\u043d\u0442\u0440.","part_quantity":8,"type":"part","node_link":"no"},"add":{"additional":"M12X1,5"}},{"standart":{"part_number":"5","part_code":"N 90924202","part_name":"\u0411\u043e\u043b\u0442","part_quantity":2,"type":"part","node_link":"no"},"add":{"additional":"M12X1,5X120"}},{"standart":{"part_number":"6","part_code":"N 01153110","part_name":"\u041f\u043e\u0434\u043a\u043b\u0430\u0434\u043d\u0430\u044f \u0448\u0430\u0439\u0431\u0430","part_quantity":"-","type":"part","node_link":"no"},"add":{"additional":"13"}},{"standart":{"part_number":"(6)","part_code":"N 01153116","part_name":"\u041f\u043e\u0434\u043a\u043b\u0430\u0434\u043d\u0430\u044f \u0448\u0430\u0439\u0431\u0430","part_quantity":"-","type":"part","node_link":"no"},"add":{"additional":"13X24X2,5"}},{"standart":{"part_number":"(7)","part_code":"8E0505324M","part_name":"P\u044b\u0447\u0430\u0433 \u043f\u043e\u0434\u0432\u0435\u0441\u043a\u0438, \u043f\u043e\u043f\u0435\u0440\u0435\u0447\u043d\u044b\u0439","part_quantity":1,"type":"part","node_link":"no"},"add":{"additional":""}},{"standart":{"part_number":"7","part_code":"8E0505323M","part_name":"P\u044b\u0447\u0430\u0433 \u043f\u043e\u0434\u0432\u0435\u0441\u043a\u0438, \u043f\u043e\u043f\u0435\u0440\u0435\u0447\u043d\u044b\u0439","part_quantity":1,"type":"part","node_link":"no"},"add":{"additional":""}},{"standart":{"part_number":"8","part_code":"8E0501541S","part_name":"C\u0430\u0439\u043b\u0435\u043d\u0442-\u0431\u043b\u043e\u043a","part_quantity":4,"type":"part","node_link":"no"},"add":{"additional":""}},{"standart":{"part_number":"9","part_code":"WHT001676","part_name":"\u0428\u0430\u0439\u0431\u0430, \u044d\u043a\u0441\u0446\u0435\u043d\u0442\u0440\u0438\u043a\u043e\u0432\u0430\u044f","part_quantity":2,"type":"part","node_link":"no"},"add":{"additional":"12,2X30X5X4"}},{"standart":{"part_number":"10","part_code":"WHT002262","part_name":"\u042d\u043a\u0441\u0446\u0435\u043d\u0442\u0440\u0438\u043a\u043e\u0432\u044b\u0439 \u0431\u043e\u043b\u0442","part_quantity":2,"type":"part","node_link":"no"},"add":{"additional":"M12X1,5X87"}},{"standart":{"part_number":"11","part_code":"N 10602202","part_name":"\u0411\u043e\u043b\u0442 \u0441 \u0448\u0435\u0441\u0442\u0438\u0433\u0440. \u0433\u043e\u043b. (\u043a\u043e\u043c\u0431\u0438)","part_quantity":2,"type":"part","node_link":"no"},"add":{"additional":"M12X1,5X75"}},{"standart":{"part_number":"12","part_code":"8E0505433C","part_name":"\u041f\u043e\u0432\u043e\u0440\u043e\u0442\u043d\u044b\u0439 \u043a\u0443\u043b\u0430\u043a","part_quantity":1,"type":"part","node_link":"no"},"add":{"additional":""}},{"standart":{"part_number":"(12)","part_code":"8E0505434C","part_name":"\u041f\u043e\u0432\u043e\u0440\u043e\u0442\u043d\u044b\u0439 \u043a\u0443\u043b\u0430\u043a","part_quantity":1,"type":"part","node_link":"no"},"add":{"additional":""}},{"standart":{"part_number":"13","part_code":"8E0505203D","part_name":"C\u0430\u0439\u043b\u0435\u043d\u0442-\u0431\u043b\u043e\u043a","part_quantity":2,"type":"part","node_link":"no"},"add":{"additional":""}},{"standart":{"part_number":"(14)","part_code":"N 90924103","part_name":"\u0411\u043e\u043b\u0442 \u0448\u0435\u0441\u0442\u0438\u0433\u0440\u0430\u043d\u043d\u044b\u0439, \u0441 \u0446\u0430\u043f\u0444\u043e\u0439 (\u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439)","part_quantity":"-","type":"part","node_link":"no"},"add":{"additional":"M12X1,5X130"}},{"standart":{"part_number":"14","part_code":"N 90625902","part_name":"\u0411\u043e\u043b\u0442 \u0448\u0435\u0441\u0442\u0438\u0433\u0440\u0430\u043d\u043d\u044b\u0439, \u0441 \u0446\u0430\u043f\u0444\u043e\u0439 (\u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439)","part_quantity":"-","type":"part","node_link":"no"},"add":{"additional":"M12X1,5X120X80"}},{"standart":{"part_number":"15","part_code":"8E0501529K","part_name":"\u041f\u043e\u043f\u0435\u0440\u0435\u0447\u043d\u0430\u044f \u0440\u0443\u043b\u0435\u0432\u0430\u044f \u0442\u044f\u0433\u0430","part_quantity":2,"type":"part","node_link":"no"},"add":{"additional":""}},{"standart":{"part_number":"(16)","part_code":"N 90924103","part_name":"\u0411\u043e\u043b\u0442 \u0448\u0435\u0441\u0442\u0438\u0433\u0440\u0430\u043d\u043d\u044b\u0439, \u0441 \u0446\u0430\u043f\u0444\u043e\u0439 (\u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439)","part_quantity":2,"type":"part","node_link":"no"},"add":{"additional":"M12X1,5X130"}},{"standart":{"part_number":"17","part_code":"N 10106402","part_name":"\u0428\u0435\u0441\u0442\u0438\u0433\u0440\u0430\u043d\u043d\u0430\u044f \u0433\u0430\u0439\u043a\u0430 \u0441 \u0431\u0443\u0440\u0442\u0438\u043a\u043e\u043c, \u0441\u0430\u043c\u043e\u043a\u043e\u043d\u0442\u0440\u044f\u0449\u0430\u044f\u0441\u044f","part_quantity":4,"type":"part","node_link":"no"},"add":{"additional":"M12X1,5"}},{"standart":{"part_number":"18","part_code":"4B0407643A","part_name":"\u0411\u043e\u043b\u0442","part_quantity":2,"type":"part","node_link":"no"},"add":{"additional":"M16X1,5X72"}},{"standart":{"part_number":"(19)","part_code":"8E0598625B","part_name":"\u041f\u043e\u0434\u0448\u0438\u043f\u043d\u0438\u043a \u0441\u0442\u0443\u043f\u0438\u0446\u044b \u0441 \u043c\u043e\u043d\u0442\u0430\u0436\u043d\u044b\u043c\u0438 \u0434\u0435\u0442\u0430\u043b\u044f\u043c\u0438","part_quantity":2,"type":"part","node_link":"no"},"add":{"additional":"82MM"}},{"standart":{"part_number":"20","part_code":"4B0407613B","part_name":"\u0421\u0442\u0443\u043f\u0438\u0446\u0430","part_quantity":2,"type":"part","node_link":"no"},"add":{"additional":""}},{"standart":{"part_number":"21","part_code":"4D0407623B","part_name":"\u041f\u044b\u043b\u0435\u0437\u0430\u0449\u0438\u0442\u043d\u0430\u044f \u0448\u0430\u0439\u0431\u0430","part_quantity":2,"type":"part","node_link":"no"},"add":{"additional":"82MM"}},{"standart":{"part_number":"22","part_code":"WHT000237","part_name":"\u0428\u0430\u0440\u0438\u043a\u043e\u0432\u044b\u0439 \u0431\u043e\u043b\u0442 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d \u0441\u0438\u043d\u0438\u043c \u0446\u0432\u0435\u0442\u043e\u043c","part_quantity":8,"type":"part","node_link":"no"},"add":{"additional":"M12X1,5X45"}}]}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-05-11
@MaratGan

parts = [ n['standart'] for n in data['parts']['parts'] ]
part_number = f'({part_number})'
part_code = next((n['part_code'] for n in parts if n['part_number'] == part_number), None)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question