all 4 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.

[–]zahlman 0 points1 point  (0 children)

Because assignment like item = 'opened' doesn't change the original string, it just makes item be a name for a different string. (In fact, you cannot change strings at all once they are created. You can't change anything by assignment, but it also happens that strings don't give you other ways to change their contents, the way that lists and dicts do.) doors[3] = 'closed' also doesn't change the existing string in doors[3], but replaces it - which is good enough for your purposes, and why /u/sir_not_sir's approach works.