Skip to content

Instantly share code, notes, and snippets.

@feifangit
Created July 24, 2013 21:48
Show Gist options
  • Save feifangit/6074888 to your computer and use it in GitHub Desktop.
Save feifangit/6074888 to your computer and use it in GitHub Desktop.
a = set([hashabledict({1:11}), hashabledict({2:22})])
b = set([hashabledict({1:11}), hashabledict({3:33})])
for i in range(3):
print "set a:", a, id(a)
copyofa = set(a)
print "shallow copy ofset a:", copyofa, id(copyofa)
delta = copyofa-b
print "delta", delta
for item in delta:
print id(item)
item[1] = "xx"
print "*"*10
#--------------result-----------------
#set a: set([{1: 11}, {2: 22}]) 70757112
#shallow copy ofset a: set([{1: 11}, {2: 22}]) 72005912
#delta set([{2: 22}])
#72099360
#**********
#set a: set([{1: 11}, {1: 'xx', 2: 22}]) 70757112
#shallow copy ofset a: set([{1: 11}, {1: 'xx', 2: 22}]) 72004472
#delta set([{1: 'xx', 2: 22}])
#72099360
#**********
#set a: set([{1: 11}, {1: 'xx', 2: 22}]) 70757112
#shallow copy ofset a: set([{1: 11}, {1: 'xx', 2: 22}]) 72006032
#delta set([{1: 'xx', 2: 22}])
#72099360
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment