Skip to content

A21 inventory  #30

Description

@darkseid-03

def create_inventory(items):
inventory_dict={}
for i in items:
if i not in inventory_dict:
inventory_dict[i]=1
elif i in inventory_dict:
inventory_dict[i]+=1
return inventory_dict

def add_items(inventory_dict,items):
for j in items:
if j in inventory_dict:
inventory_dict[j]+=1
if j not in inventory_dict:
inventory_dict[j]=1
return inventory_dict

def decrement_items(inventory_dict,items):
for j in items:
inventory_dict[j]-=1
if inventory_dict[j]<0:
inventory_dict[j]=0
return inventory_dict

def remove_item(inventory_dict,item):
item_List=list(inventory_dict.keys())
for i in item_List:
if i==item:
inventory_dict.pop(i,None)
return inventory_dict

def list_inventory(inventory_dict):
inventory_list=[]
for key in inventory_dict:
inventory_tuple=()
if inventory_dict[key]>0:
inventory_list.append((key,)+(inventory_dict[key],))
return inventory_list

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions