Hello c:
I'm trying to create a diction that counts the amount of times an item reoccurs in a list and put the result in a diction with the respective item.
here is my code:
def create_inventory(items):
"""Create a dict that tracks the amount (count) of each element on the items list.
:param items: list - list of items to create an inventory from.
:return: dict - the inventory dictionary.
"""
di = dict()
for i in items:
di = {i:items.count(i)}
return di
here is my error message:
AssertionError: {'diamond': 2} != {'wood': 1, 'iron': 2, 'diamond': 2}
- {'diamond': 2}
- {'diamond': 2, 'iron': 2, 'wood': 1} : Called create_inventory(["wood", "iron", "iron", "diamond", "diamond"]). The function returned {'diamond': 2}, but the tests expected {'wood': 1, 'iron': 2, 'diamond': 2}.
it looks like it is only making one entry in the diction for the last item. I can't figure out how to save each item and count value.