2021年3月26日星期五

Compare 2 unsorted lists of dictionaries

I have 2 lists of dictionaries. Keys on both of the lists are particularly not same except one. I need to compare both of them based on that 1 key which is same.

I need to compare the lists based on product_id in the dictionaries.

These dictionaries are also not sorted in the list for example dictionary in list1 with product_id = EJFMV could be the 3rd element in the list while dictionary in list1 with product_id = EJFMV could be the 7th element in the list.

Sorting dictionaries is the list is also not possible for various other reasons.

list1

[{'id': 18, 'product_id': 'EJFMV', 'product_name': 'FRESH MILK 500ML', 'product_description': 'Our milk is free of chemical, pesticides and preservatives. We are committed to provide hygienic and healthy milk every time you order from us.', 'product_images': 'productImages/Fresh_Milk_500_ml.png', 'product_price': 31.0, 'product_status': None, 'discount': None, 'rating': None, 'status': False, 'subscription': True, 'gst': 0, 'created_at': '2020-11-19T10:58:30Z', 'updated_at': '2021-03-10T10:54:50.885980Z'}]      

list2

[{'product_id': 'SVETU', 'product_name': 'BUTTER 200 GM', 'product_description': 'A well churned out authentic butter from Punjab Sind Foods will make your parathas tastier than ever before.', 'product_images': '/images/productImages/white_butter.png', 'product_price': 115.0, 'gst': 0, 'product_status': None, 'discount': None, 'rating': None, 'product_quantity': 1, 'get_product_total': 115.0, 'get_product_total_gst': 0.0}]  

Note - Posted full list so everyone has an idea what I'm talking abut

https://stackoverflow.com/questions/66827923/compare-2-unsorted-lists-of-dictionaries March 27, 2021 at 12:08PM

没有评论:

发表评论