Dictionary object functionality in python

Previous
Next

Dictionary object is providing set of functions which are used process elements of that dictionary.

Code:

accounts ={101:"harin", 102:"kiritin", 103:"ramya", 104:"annie"}
print("Accounts :", accounts)
#list of keys will be returned
print("Keys :", accounts.keys())
#returns list of values
print("Values :", accounts.values())
accounts.pop(102)
print("After removal of 102 :", accounts)
accounts.popitem()
print("After removal of last inserted element :", accounts)
print("Value at 103 :", accounts.get(103))

Output:

Accounts : {101: 'harin', 102: 'kiritin', 103: 'ramya', 104: 'annie'}
Keys : dict_keys([101, 102, 103, 104])
Values : dict_values(['harin', 'kiritin', 'ramya', 'annie'])
After removal of 102 : {101: 'harin', 103: 'ramya', 104: 'annie'}
After removal of last inserted element : {101: 'harin', 103: 'ramya'}
Value at 103 : ramya
Previous
Next

Add Comment

Courses Enquiry Form