Implemented function for counting items in an inventory.