Files

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 KeyError when a key is missing by using a dict method that takes a default value as one of its arguments.
  • It is also possible to accomplish the same thing manually in the loop by using some checking and error handling, but the dict method 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 dict with keys.
  • This dict method returns a new dictionary, populated with default values. If no value is given, the default value will become None

3. Update Recipe "Ideas" Section

  • Don't overthink this one! This can be solved in one dict method 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 list or a tuple, what built-in function 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_cart might be handy for adding in items.
  • Looping through 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 value of a given key by using <dict name>[<key_name>] syntax.
  • If you had a list or a tuple, what built-in function might you use to sort them?
  • Remember that the built-in function can take an optional reverse=True argument.

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.