#Python demonstrate hashtable usage
#Python dictionary
items1 = dict({"key1": 1, "key2": "two", "key3": 3})
print(items1) #print all items
#Python empty dictionary
items2 = {}
items2["key1"] = 1
items2["key2"] = 2
items2["key3"] = 3
print(items2)
#Python if key not in dictionary
#uncomment to run i.e remove the hashtag in front of print
#print(items2["key6"])
#Python dictionary update
items2["key2"] = "two"
print(items2)
#Python iterate dictionary
for key, value in items2.items():
print("Key: ", key, "Value: ", value)
-------------------------------------------------------------------------------
#Output
{'key1': 1, 'key2': 'two', 'key3': 3}
{'key1': 1, 'key2': 2, 'key3': 3}
{'key1': 1, 'key2': 'two', 'key3': 3}
Key: key1 Value: 1
Key: key2 Value: two
Key: key3 Value: 3
Comments
Post a Comment