I am trying to pass a dictionary to a function so that it is the function's first parameter and that type checking occurs to verify that a dictionary has indeed been submitted.
fridge = {"cheese":10, "milk":11, "feta":12, "cream":21, "onion":32, "pepper":14}
def fridge_validation(fridge):
if not isinstance (fridge,dict) :
raise TypeError: ("require a valid dictionary to be submitted!")
I thought the following would work....
def dummy (fridge):
return fridge
test_of_dummy=dummy ({"cheese", "milk", "eggs"})
print (test_of_dummy)
{'eggs', 'milk', 'cheese'} (this was what was printed)
Not quite sure if I have done it correctly? Also.... I am confused by the following.
def dummy (fridge):
fridge={}
return fridge
test_of_dummy=dummy ({"cheese", "milk", "eggs"})
print (test_of_dummy) "{}" was outputted...
.
but I thought I had already passed on the variables...? So why is the {} seemingly taking precedence over the test_of_dummy ?
As to what I am trying to do....
1) Pass a dictionary called fridge as the 1st parameter to a function. Use isinstance and type error to confirm the dictionary is indeed a dictionary.
2) Have a second function that will subtract from the fridge dictionary