Tag: Value
How to remove elements from a List based on value or External Criterion
In this article we will discuss how to remove an element from a List by matching a value or by matching some criterion. std::list provides two member functions for removing elements based on value i.e. std::list::remove and std::list::remove_if. Advertisements Using std::list::remove to remove element by value void remove (const value_type& val); It removes all the elements …
How to remove elements from a List based on value or External CriterionRead More
How to Sort a Map by Value in C++
In this article we will discuss how to sort a map by value in both ascending and descending order. A Map store the elements in the sorted order of keys. Advertisements For example, we have a map of words and its frequency count as key – value pair i.e. std::map<std::string, int> mapOfWordCount ; Now lets insert following …
How to search by value in a Map | C++
In this article will discuss how to search for all the elements in map with given value. Map internally store elements in Key-Value pair. In which keys are unique but values can be duplicate. There are member functions to search pairs by key i.e. std::map::find(). But there is no direct function to search for all …
C++ Map: Erase by Value or Callback while iterating | erase_if for map
In this article we will discuss two different ways to erase elements from map i.e. In previous article we discussed how to erase elements by key and iterator using member function std::map::erase. But there is no default function to delete elements by value instead of key or delete elements based on callback. Advertisements We will …
C++ Map: Erase by Value or Callback while iterating | erase_if for mapRead 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
Java: How to get all keys by a value in HashMap ? | Search by Value in Map
In this article we will discuss how to search into a Map by value and fetch associated keys to the given value. Suppose we have a map of string and integers i.e. Advertisements HashMap<String, Integer> mapOfWords = new HashMap<String, Integer>() { { put(“John”, 25); put(“at”, 2); put(“from”, 10); put(“is”, 5); put(“the”, 2); put(“hello”, 1); put(“break”, …
Java: How to get all keys by a value in HashMap ? | Search by Value in MapRead More
Python : How to Check if an item exists in list ? | Search by Value or Condition
In this article we will discuss different ways to check if a given element exists in list or not. Table of Contents Introduction Check if element exists in list using python “in” Operator Check if element exist in list using list.count() function Check if element exist in list based on custom logic Introduction Suppose we …
Python : How to Check if an item exists in list ? | Search by Value or ConditionRead More
Python : How to remove element from a list by value or Index | remove() vs pop() vs del
In this article we will discuss different ways to remove an elements from list. Remove an element from List by value using list.remove() Python’s list provides a member function to remove an element from list i.e. Advertisements list.remove(value) It removes the first occurrence of given element from the list. For example, Frequently Asked: Convert a …
Python : How to remove element from a list by value or Index | remove() vs pop() vs delRead More
Python : How to find keys by value in dictionary ?
In this article we will discuss how to find all keys associated with a given single value or multiple values. Suppose we have a dictionary of words and thier frequency i.e. Advertisements # Dictionary of strings and int dictOfWords = { “hello”: 56, “at” : 23 , “test” : 43, “this” : 97, “here” : …
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