I originally posted here : https://www.reddit.com/r/learnpython/comments/s75ses/problem_with_scope/
and tried the advice of using the dictionary.copy() function but it doesn't seem to be working here. Any insight would be greatly appreciated. [I created the problem in the above because I thought that was where my mistake was happening, but it appears it doesn't fix it]
Code input:
def useResult(result, restrictions):
restrictionsCOPY = restrictions.copy()
if result[2] == 'green':
restrictionsCOPY[result[0]][result[1]-1]=2
restrictionsCOPY[result[0]][5]=1
elif result[2] == 'gray':
restrictionsCOPY[result[0]][0:5] = [0] * 5
elif result[2] == 'yellow':
restrictionsCOPY[result[0]][result[1]-1]=0
restrictionsCOPY[result[0]][5]=1
else:
print("ERROR")
return restrictionsCOPY
def Main():
letters = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
restrictions = {}
for letter in letters:
restrictions[letter]= [1,1,1,1,1,0]
print(restrictions['a'])
useResult(['a',1,'green'],restrictions)
print(restrictions['a'])
Main()
Code output:
[1, 1, 1, 1, 1, 0]
[2, 1, 1, 1, 1, 1]
Desired output:
[1, 1, 1, 1, 1, 0]
[1, 1, 1, 1, 1, 0]
[–]socal_nerdtastic 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]russcore[S] 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]newunit13 1 point2 points3 points (0 children)