I'm trying to create a dictionary of lists for an inventory. Example I add 'fruits', 'vegetables', 'drinks'
as keys of a dictionary then I create a list for each of them. Once created, I add two items (e.g. 'apple','manggo')
for each list so I can print them out like this:
fruits is list
items in fruits are apple, manggo
veggies is list
items in veggies are cabbage, cucumber
drinks is list
items in drinks are iced tea, juice
However I am unable to identify the items of newly created list and I only get this:
fruits is list
items in fruits are fruits
My code:
class Inventory:
def __init__(self):
self.dict_inv = dict()
self.count_inv = int(input("Enter the number of inventories: "))
for count in range(self.count_inv):
self.name_inv = str(input("Enter Inventory #%d: " % (count+1)))
self.dict_inv[self.name_inv] = count
self.name_inv = list()
sample_add = str(input("Add item here: "))
self.name_inv.append(sample_add)
sample_add2 = str(input("Add another item here: "))
self.name_inv.append(sample_add2)
for keys in self.dict_inv.keys():
if type([keys]) is list:
print("%s is list" % keys)
print("items in %s are %s" % (keys,str(keys)))
Inventory()