Download pricebook_tester.py
The six required functions are:
is_sorted(pricebook) \(O(N)\)price_average(pricebook) \(O(N)\)unsorted_get(pricebook, name) \(O(N)\)unsorted_put(pricebook, name, price) \(O(N)\)sorted_get(pricebook, name) \(O(\log N)\)sorted_put(pricebook, name, price) \(O(N)\)Lists of Tuples: pricebook representation
First item (at index zero) is the price, second item (at index 1) is name
There’s no need for nested for loops when you know the first position of each tuple (index zero) is price and the second position (index one) is product name.
You can index the tuple in a for loop to get each price or name:
unsorted_put is asked to change a price of an existing product name, you need to remove the existing tuple from the list of products, and append a new tuple with the new price for that existing product name.