Use del:
dict2 = {"key1":"value1","key2":"value2","key3":"value3"}
print "############### print before del#################"
for k in dict2.keys():
myValue = dict2[k]
print "key: %s , value: %s" % (k,myValue)
del dict2["key2"]
print "############### print after del#################"
for k in dict2.keys():
myValue = dict2[k]
print "key: %s , value: %s" % (k,myValue)
Resource:
http://stackoverflow.com/questions/5844672/delete-an-element-from-a-dictionary
dict2 = {"key1":"value1","key2":"value2","key3":"value3"}
print "############### print before del#################"
for k in dict2.keys():
myValue = dict2[k]
print "key: %s , value: %s" % (k,myValue)
del dict2["key2"]
print "############### print after del#################"
for k in dict2.keys():
myValue = dict2[k]
print "key: %s , value: %s" % (k,myValue)
Resource:
http://stackoverflow.com/questions/5844672/delete-an-element-from-a-dictionary
No comments:
Post a Comment