I've got three python lists which I want to make into a dictionary, then join those three dictionaries to one based on the key values.
My python lists are made like this:
with open ('full_product_shipments.xml','r') as file2:
full_product_shipments = list([line.strip().replace('{"','').replace('}','').replace('"','').replace(':',',').split(',') for line in file2])
And they look like this :
list1
[['transaction_id', '224847627', 'product_amount', '2.73', 'user_invoice_date', '2018-12-21'],
['transaction_id', '67919397', 'product_amount', '2.73', 'user_invoice_date', '2017-10-26']]
list2
[['tracking_code', '29285908', 'from_country', 'FR', 'to_country', 'FR', 'package_type_id', '10', 'transaction_id', '172238850', 'shipping_label_created', '2018-09-25 18', '40', '52'],
['tracking_code', '22105784', 'from_country', 'FR', 'to_country', 'FR', 'package_type_id', '10', 'transaction_id', '111423825', 'shipping_label_created', '2018-04-13 11', '22', '44']]
list3
[['tracking_code', '21703238', 'from_country', 'FR', 'to_country', 'FR', 'amount', '3.23'],
['tracking_code', '41545695', 'from_country', 'FR', 'to_country', 'FR', 'amount', '2.9']]
list1 and list2 both have transaction_id
on which I would need to join them once I convert them to a dict.
The newly joined list (list1 and list2) and list3 both have tracking_id
by which I want to join them once list3 is converted to a dict.
I've tried using this :
result=[x.update(amount=y['amount']) for x in full_product_shipments for y in full_provider_invoices if x['transaction_id'] == y['transaction_id']]
But that throws me an TypeError:
TypeError: list indices must be integers or slices, not str
Maybe there is no need to convert everything to dict. I'm kind of new to python so if there is a better way to merge information based on key, I would be very appreciated to learn it.