From the course: Python Data Structures: Sets and Frozen Sets

Unlock this course with a free trial

Join today to access over 24,100 courses taught by industry experts.

Solution: Composite key search

Solution: Composite key search

- [Instructor] You are given a data set consisting of customer details, customer order details, product, and customer details, and a function that is search_product_names. It accepts two parameters, customer_id and order_id. Now also observe that at the end, we have to find product names, but our original dictionary does not contain the product names. And here, you are not given the product_id as the parameter. So how would you go about solving it? First, let us create a variable key, and key will be frozenset containing customer_id and order_id. Search if key exists in the customer_orders dictionary. If the key exists in customer_orders dictionary, fetch the product list. This will be list of dictionaries. This will have product_id for each of the purchased_products. So for purchased_products, this is tmp_products is list of dictionaries, purchased_products is dictionary, purchased products is dictionary. What we want is product_id because products dictionary has product_id as the…

Contents