I have a list with dictionary inside, with the following keys: id, external_id_client, product_id, as below:
[{'id': 3, 'external_id_client': '7298', 'product_id': 13},
{'id': 3, 'external_id_client': '7298', 'product_id': 8},
{'id': 4, 'external_id_client': '3', 'product_id': 12},
{'id': 4, 'external_id_client': '3', 'product_id': 9},
{'id': 5, 'external_id_client': '4', 'product_id': 12}]
I need that if the ID and external_id are repeated and I have information in the product_id key it creates a tuple in the product_id.
Expected output:
[{'id': 3, 'external_id_client': '7298', 'product_id': (13, 8)},
{'id': 4, 'external_id_client': '3', 'product_id': (12, 9)},
{'id': 5, 'external_id_client': '4', 'product_id': (12)}]
How can I do this?