Hello! Coul someone explain why this code gets an error " ValueError: too many values to unpack"?

available_items = {"health potion": 10, "cake of the cure": 5, "green elixir": 20, "strength sandwich": 25, "stamina grains": 15, "power stew": 30}
health_points = 20

for key,value in available_items:
  health_points += value

Traceback (most recent call last): File "script.py", line 7, in for i,j in available_items: ValueError: too many values to unpack (expected 2)

1 answer

  • answered 2020-05-22 12:29 0buz


    for key,value in available_items.items():

    for key,value in available_items alone will only iterate keys.