Need help removing dictionary key:value and returning it to another dictionary

I am trying to take a key:value from a dictionary “inventory” remove it from the dictionary using “.pop(key)” add the key’s value to a variable and then add that removed key:value to another dictionary. I posted my attempt below, please help with suggestions of how to do this.

inventory = {“minor health potion”: 40, “major health potion”: 70, “expert health potion”: 100, “minor stamina potion”: 40, “major stamina potion”: 70, “expert stamina potion”: 100, “blunted sword”: 8, “sharpened sword”: 14, “honed sword”: 20, “splintered shield”: 12, “reinforce shield”: 20, “steel shield”: 30}

health = 20
stamina = 50
attack = 5
armor = 15

def use_item(item, attribute, gone, name):
used_items = {}
if item.pop(gone):
attribute += item.pop(gone)
return attribute, used_items.append(used_items[name])

print(use_item(inventory, health, “minor health potion”, “potion”))

#this is the error I get back in the terminal:
Traceback (most recent call last):
File “dictionaries.py”, line 18, in
print(use_item(inventory, health, “minor health potion”, “potion”))
File “dictionaries.py”, line 14, in use_item
attribute += item.pop(gone)
KeyError: ‘minor health potion’

The assumption is that we know the key, so,

new_dict[key] = old_dict.pop(key)

The item will be removed from old_dict, and the popped value assigned to the new_dict.

Thank you for replying.
I have figured that part out, however I don’t know how to also (before, during, or after) add the value of that key to my variable.
for instance:
new_dict[key] = variable += old_dict.pop(key)

That should raise an error since the assignment is a statement.

variable += old_dict.pop(key)    # a statement

it’s not necessary to use a variable, if we write it the way shown earlier

new_dict[key] = old_dict.pop(key)

But if there is some other use for the variable that justifies using it, then

variable = old_dict.pop(key)
new_dict[key] = variable

or if the variable is being accumulated,

variable += old_dict.pop(key)

and that value can be given to the key in the new dictionary

new_dict[key] = variable.

From looking at your code, I think I understand what you are trying to do. I have a suggestion to take a slightly different approach. The following link will take you to a site called pythontutor.com where you will see your code with a couple of modifications. Click on the button labeled Visualize Execution. You’ll see a new screen with your code on the left, and output on the right. Click on the button labelled Forward >, and you can step through the code line by line, and see a visualization of what is happening on the right. Let me know if this is what you were going for.
Link: https://rebrand.ly/bnbfgv