Skip to content

Instantly share code, notes, and snippets.

@AndySum
Last active December 22, 2015 04:59
Show Gist options
  • Save AndySum/6421240 to your computer and use it in GitHub Desktop.
Save AndySum/6421240 to your computer and use it in GitHub Desktop.
This is a fragment of some Python code within a function. I can't understand why it changes the value at key (5,4) and (5,5). When I try this isolated example in a normal compiler it works. how come I get this output?!?
node = (5,4)
direction = "South"
print "moves is",moves
print "i'm going to add",direction,"at",node
moves[node].append(direction)
print "moves is",moves
sys.exit("fuck this")
#Output
'''
moves is {(5, 4): [], (5, 5): []}
i'm going to add South at (5, 4)
moves is {(5, 4): ['South'], (5, 5): ['South']}
fuck this
'''
@AndySum
Copy link
Author

AndySum commented Sep 3, 2013

I expect to get: moves is {(5, 4): ['South'], (5, 5): []}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment