- The Python Dictionary Tutorial can be a great place to start.
- The Python docs on Mapping Types - dicts is also pretty helpful.
- You need a for loop to iterate the list of items, then insert each item in the dictionary if missing and increment the item count using the dictionary accessor.
- You can use
dict.setdefaultto make sure the value is set before incrementing the count of the item. - This function should return a dict.
- You need a for loop to iterate the list of items, then insert each item if not already in the dictionary and increment the item count using the dictionary accessor.
- You can use
dict.setdefaultto make sure the value is set before incrementing the count of the item. - The function
add_itemscan be used by thecreate_inventoryfunction with an empty dictionary in parameter. - This function should return a dict.
- You need for loop to iterate the list of items, if the number of items is not
0then decrement the current number of items. - You can use the check
key in dictthat returnsTrueif the key exists to make sure the value is in the dictionary before decrementing the number of items. - This function should return a dict.
- If item is in the dictionary, remove it.
- If item is not in the dictionary, do nothing.
- This function should return a dict.
- You need to use a for loop on the inventory and if the number of item is greater of
0then append thetupleto alist. - You can use
dict.items()to iterate on both the item and the value at the same time,items()returns atuplethat you can use or deconstruct, if needed. - This function should return a list of tuples.