Tag: key
Finding all values for a key in multimap using equals_range – Example
Multimap store elements in key value pair. It can also have duplicate keys. There can be many scenarios when we want to find all the values associated with a key in multimap. For example, we have a multimap of char & int as key value pair and initialzed with following values i.e. Advertisements {‘a’, 1}, {‘b’, …
Finding all values for a key in multimap using equals_range – ExampleRead More
How check if a given key exists in a Map | C++
In this article we will discuss how to find if a given key exists in map or not. Map internally store elements in Key-Value pair. It provides 2 member functions to check if a given key exists in map i.e. Advertisements std::map::find std::map::count Check if map contains a key using std::map::count std::map provides a member …
C++ map : Erase element by key or Iterator or Range
In this article we will discuss the different ways to delete a key-value pair from map. std::map provides 3 overloaded version of erase() to remove elements from map i.e. Advertisements Erase by key Erase by Iterator Erase a range Lets discuss them one by one, Erase Element from Map by Key std::map provides a erase function that accepts …
C++ map : Erase element by key or Iterator or RangeRead More
Java : Creating HashMap by associating multiple values with same Key
In this article we will discuss how to create a HashMap with multiple values associated with same Key in Java. Suppose we want to create a HashMap to keep the track of strings and their occurrences in text. For example. Advertisements “the” occurred at following indexes 1,4,8,12. “at” occurred at following indexes 22, 28, 44 …
Java : Creating HashMap by associating multiple values with same KeyRead More
Java : How to update the value of an existing key in HashMap | put() vs replace()
In this article we will discuss different ways to update the value of an existing key in HashMap in Java. Suppose we have a HashMap of words and their frequency count i.e. Advertisements // Create a Map of words and their frequency count HashMap<String, Integer> mapOfWords = new HashMap<String, Integer>() { { put(“John”, 25); put(“at”, …
Java : How to update the value of an existing key in HashMap | put() vs replace()Read More
Remove key from Dictionary in Python
In this article we will discuss 6 different ways to delete a key from a dictionary in python. Subscribe Table Of Contents Remove a key from a dictionary using dict.pop() Delete a Key from dictionary if exist using pop() Remove a key from a dictionary using items() & for loop Remove a key from a …
Python : How to Sort a Dictionary by key or Value ?
In this article we will discuss how to sort the contents of dictionary by key or value. Suppose we have a dictionary of string and ints i.e. Advertisements # Dictionary of strings and ints wordsFreqDict = { “hello”: 56, “at” : 23 , “test” : 43, “this” : 43 } Dictionary is like a hash …
Python : How to Sort a Dictionary by key or Value ?Read More
Python : **kwargs | Functions that accept variable length key value pair as arguments
In this article we will discuss how to create functions in Python that can accept variable length arguments in key value pair format. Suppose we want to define a function that will print the provided students details. Details will be in key value pairs, where key represents the property name and value as property’s value. …
Python : **kwargs | Functions that accept variable length key value pair as argumentsRead More
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 …
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 …