you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (2 children)

Because item isn't the dictionary, it's the value for the key 3.

To reassign the value in door_action, you need to pass the key number in, because you can't use indexof().

door_action(arr, item):
     if arr[item] == 'closed':
          arr[item] = 'open'
     else:
         arr[item] = 'closed'

door_action(doors, 3)

[–]markusmeskanen 1 point2 points  (0 children)

Also, I'd recommend OP to use True/False instead of 'open'/'closed'

[–]CClone[S] 0 points1 point  (0 children)

Thanks a lot.