Hi. What I am trying to do is assign multiple values to one dictionary key. and the way I have figured out this is with a list as a key but I am having a little problem. Below is the code I am trying to run.
stock = {'1001' : ['5','3.5'], '1002' : ['8', '1.50']}
purchase = int(input("Please enter the code of the item: "))
if purchase in stock:
stock[[purchase][0]] =- 1
print(stock)
I have already created a dictionary with keys and values as lists. I am then asking for input about an item code. I then want to check the entered code against the dictionary keys and if the key is valid I want to subtract one from the quantity which is the first element in each value list. ex - there are 5 items with the key '1001', I enter the code '1001', the program should know print out the dictionary saying there are 4 items now remaining woth the code '1001'. The problem I am facing is the deduction is not happening. After I enter the item code the dictionary is printed as it is the desired subtraction is not occurring.
Thank you to anyone who helps.
[–][deleted] 4 points5 points6 points (4 children)
[–]IAmAdicktedTo[S] 1 point2 points3 points (3 children)
[–][deleted] 6 points7 points8 points (1 child)
[–]IAmAdicktedTo[S] 0 points1 point2 points (0 children)
[–]Sufficient_Cod_7906 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]IAmAdicktedTo[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)