"""Functions to keep track and alter inventory."""fromcollectionsimportCounterdefcreate_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.
"""returndict(Counter(items))defadd_items(inventory,items):"""Add or increment items in inventory using elements from the items `list`.
:param inventory: dict - dictionary of existing inventory.
:param items: list - list of items to update the inventory with.
:return: dict - the inventory updated with the new items.
"""foriteminitems:ifitemininventory:inventory[item]+=1else:inventory[item]=1returninventorydefdecrement_items(inventory,items):"""Decrement items in inventory using elements from the `items` list.
:param inventory: dict - inventory dictionary.
:param items: list - list of items to decrement from the inventory.
:return: dict - updated inventory with items decremented.
"""foriteminitems:ifitemininventory:ifinventory[item]<=1:inventory[item]=0else:inventory[item]-=1returninventorydefremove_item(inventory,item):"""Remove item from inventory if it matches `item` string.
:param inventory: dict - inventory dictionary.
:param item: str - item to remove from the inventory.
:return: dict - updated inventory with item removed. Current inventory if item does not match.
"""ifitemininventory:inventory.pop(item)returninventorydeflist_inventory(inventory):"""Create a list containing only available (item_name, item_count > 0) pairs in inventory.
:param inventory: dict - an inventory dictionary.
:return: list of tuples - list of key, value pairs from the inventory dictionary.
"""item_list=[]forkey,valueininventory.items():ifvalue>0:item_list.append((key,value))returnitem_list