Tag: Dictionary
Python: Dictionary with multiple values per key
In this article, we will discuss how to create and manage a dictionary in which keys can have multiple values. In python, if we want a dictionary in which one key has multiple values, then we need to associate an object with each key as value. This value object should be capable of having various …
Python: Check if dictionary is empty
In this article we will discuss different ways to check if a dictionary is empty or not. These two ways to check if a python dictionary is empty or not, By casting dictionary to bool in if statement. Using len() function. Suppose we have two dictionaries: The first dictionary contains strings as keys and integers …
How to get first key in Dictionary – Python
In this article we will discuss different ways to fetch the first key of a dictionary. Then we will look how to select first N keys of a dictionary in python. Table of contents Get first key from a dictionary using keys() method. Get first key in a dictionary using iter() & next(). Get first …
Python: Get first value in a dictionary
In this article we will discuss different ways to fetch the first value of a dictionary. Then we will look how to select first N values of a dictionary in python. Table of Contents: Get first value in a python dictionary using values() method. Get first value in a python dictionary using item(). Get first …
Get first key-value pair from a Python Dictionary
In this article, we will discuss different ways to fetch first key-value pair from a dictionary. Then we will also learn about a way to get first N key-value pairs from a python dictionary. Table of Contents Get first key-value pair of dictionary in python using iter() & next(). Get first key-value pair of dictionary …
Python: Iterate over dictionary with index
In this article, we will discuss different ways to iterate over a dictionary by index. Table of Contents Overview of enumerate() Iterate over all key-value pairs of dictionary by index Iterate over all keys of dictionary by index Iterate over all values of dictionary by index For iterating over a sequence by indexing, we can …
Python: Print all values of a dictionary
In this article, we will discuss different ways to print all values of dictionary. Then we will also cover the scenario, where we need to print all the values of a nested dictionary i.e. dictionary of dictionaries. Print all values of a python dictionary using for loop In Python, the dictionary class provides a function …
Python: Print all keys of a dictionary
In this article, we will discuss different ways to print all keys of a dictionary. Then we will also cover the scenario, where we need to print all the keys of nested dictionary i.e. dictionary of dictionaries. Print all keys of a python dictionary using for loop In Python, the dictionary class provides a function …
Python: Print all key-value pairs of a dictionary
In this article, we will learn about different ways to print all items (key-value pairs) of a dictionary. Subscribe Table of Contents Print all pairs of dictionary using for loop and items() Print all pairs of dictionary by iterating over keys only Print all pairs of dictionary in reverse order Print all key-value pairs of …
Python: Print Specific key-value pairs of dictionary
In this article, we will discuss different ways to print specific key-value pairs of a dictionary. We can either use indexing or conditions to select few pairs from a dictionary and print them. Table of Contents Print specific key-value pairs from dictionary using indexing. Print first Key-value pair of dictionary. Print last Key-value pair of …
Python: Print Specific key-value pairs of dictionaryRead More