Sayantan's Blog On Python Programming

PYTHON DICTIONARY SORTING OPERATIONS

PYTHON DICTIONARY SORTING OPERATIONS INTRODUCTIONS Python dictionaries can be sorted either in forward or backward direction by using below methods: sorted() Function sorted() function is used to sort all the keys and values of a dictionary. PYTHON DICTIONARY SORTING OPERATIONS : Output In the above example we have used the sorted() function to sort the …

PYTHON DICTIONARY SORTING OPERATIONS Read More »

REMOVING ITEMS FROM PYTHON DICTIONARIES

REMOVING ITEMS FROM PYTHON DICTIONARIES INTRODUCTION There are three methods available in Python for removing items from the dictionary. del command del command is used to delete an existing key from the dictionary. REMOVING ITEMS FROM PYTHON DICTIONARIES : Output In the above example, we have deleted the keys C and D from the dictionary …

REMOVING ITEMS FROM PYTHON DICTIONARIES Read More »

UPDATING PYTHON DICTIONARIES

UPDATING PYTHON DICTIONARIES INTRODUCTIONS Like inserting new items in the dictionary, we can modify the dictionaries as well. Updating existing dictionary value UPDATING PYTHON DICTIONARIES : Output In the above example, we have updated the value of key “E“. UPDATING PYTHON DICTIONARIES : Output In the above example, we have modified the values against keys …

UPDATING PYTHON DICTIONARIES Read More »

PYTHON DICTIONARY DEEP COPY OPERATION

PYTHON DICTIONARY DEEP COPY OPERATION INTRODUCTION In deep copy operation, changes in original dictionary does not have the impact on copied dictionary and vice-versa. There are four ways we can create deep copy in Python. Dictionary Slicing Operation importing itertools module PYTHON DICTIONARY DEEP COPY OPERATION : Output In the above example, we have used …

PYTHON DICTIONARY DEEP COPY OPERATION Read More »

PYTHON DICTIONARY SHALLOW COPY OPERATION

PYTHON DICTIONARY SHALLOW COPY OPERATION INTRODUCTION There are two types of copy operations are available in Python. In this article we will discuss on SHALLOW copy operations. Shallow copy operation represents that if we change or modify any of the dictionary then the other dictionary will also be impacted. There are several ways we can …

PYTHON DICTIONARY SHALLOW COPY OPERATION Read More »

ADDING NEW ITEMS IN PYTHON DICTIONARY

ADDING NEW ITEMS IN PYTHON DICTIONARY INTRODUCTION Python has provided us a group of built-in methods for Dictionary manipulation. Below are the methods for adding new items in the dictionary. Assignment Operator ADDING NEW ITEMS IN PYTHON DICTIONARY : Output In the above example, we have used assignment operator to add a new key value …

ADDING NEW ITEMS IN PYTHON DICTIONARY Read More »

PYTHON NESTED DICTIONARIES

PYTHON NESTED DICTIONARIES INTRODUCTION Key and value pair both can be of different data type in python dictionaries. Keys can be of string data type and values can be of complex data type. Accessing Values Using Keys PYTHON NESTED DICTIONARIES : Output In the above example, we have used list item as values which is …

PYTHON NESTED DICTIONARIES Read More »

PYTHON MIXED KEY VALUE IN DICTIONARY

PYTHON MIXED KEY VALUE IN DICTIONARY INTRODUCTION Key and value pair both can be of different data type in python dictionaries. Keys can be of string data type and values can be of number data type or vice-versa. Accessing Values Using Keys PYTHON MIXED KEY VALUE IN DICTIONARY : Output In the above example, we …

PYTHON MIXED KEY VALUE IN DICTIONARY Read More »

PYTHON STRING KEY VALUE IN DICTIONARY

PYTHON STRING KEY VALUE IN DICTIONARY INTRODUCTION Key and value pair both can be string in python dictionaries. Accessing Values Using Keys PYTHON STRING KEY VALUE IN DICTIONARY : Output In the above example, we have accessed all the values against keys in dictionary dict_class_wise_prog. Using values() function PYTHON STRING KEY VALUE IN DICTIONARY : …

PYTHON STRING KEY VALUE IN DICTIONARY Read More »