python dict set value code example
Example 1: how to set a key of dict in python
dictionary={'Hello':3,'World!':4}
def dict_add(obj,key,value):
obj[key]=value
reutrn obj
dict_add(dictionary,'Python',10)
print (dictionary)
Example 2: how to get element from dictionary python
dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
dict['Age'] = 8;
dict['School'] = "DPS School";
print "dict['Age']: ", dict['Age']
print "dict['School']: ", dict['School']
Example 3: python dictionary value as set
word_dict = dict()
word_dict["foo"] = set()
word_dict["foo"].add("baz")
word_dict["foo"].add("bang")