3.3 KiB
3.3 KiB
Hints
General
Remember, this is an MVP. That means you don't need to get too fancy with error handling or different "edge case" scenarios. It's OK to be simple and direct with the functions you are writing.
The dictionary section of the official tutorial and the mapping type official library reference are excellent places to look for more help with all these methods.
1. Add Item(s) to the Users Shopping Cart
- You will need to iterate through each item in
items_to_add. - You can avoid a
KeyErrorwhen a key is missing by using adictmethod that takes a default value as one of its arguments. - It is also possible to accomplish the same thing manually in the
loopby using some checking and error handling, but thedictmethod is easier.
2. Read in Items Listed in the Users Notes App
- Remember, Python's got a method for everything. This one is a classmethod that's an easy way to populate a
dictwith keys. - This
dictmethod returns a new dictionary, populated with default values. If no value is given, the default value will becomeNone
3. Update Recipe "Ideas" Section
- Don't overthink this one! This can be solved in one
dictmethod call. - The key word here is .... update.
4. Sort the Items in the User Cart
- What method would you call to get an iterable view of items in the dictionary?
- If you had a
listor atuple, whatbuilt-infunction might you use to sort them? - The built-in function you want is the one that returns a copy, and doesn't mutate the original.
5. Send User Shopping Cart to Store for Fulfillment
- Having a fresh, empty dictionary here as the
fulfillment_cartmight be handy for adding in items. Loopingthrough the members of the cart might be the most direct way of accessing things here.- What method would you call to get an iterable view of just the keys of the dictionary?
- Remember that you can get the
valueof a given key by using<dict name>[<key_name>]syntax. - If you had a
listor atuple, whatbuilt-infunction might you use to sort them? - Remember that the
built-infunction can take an optionalreverse=Trueargument.
6. Update the Store Inventory to Reflect what a User Has Ordered.
- There is a method that will give you an iterable view of (
key,value) pairs from the dictionary. - You can access an item in a nested tuple using bracket notation:
<tuple>[<nested_tuple>][<index_of_value>] - Don't forget to check if an inventory count falls to zero, you'll need to add in the "Out of Stock" message.