Tag: iterating
Iterating over a range of User Defined objects and calling member function using std::for_each
In this article we will discuss how to iterate over a container of user defined objects and call a member function on each of the iterating element.Suppose you have a vector of Employee class objects and you want to call a member function on each of the element in vector. [showads ad=inside_post] Let’s see how …
How to remove elements from a List while Iterating
In this article we will see how to delete an element from a list while iterating through it. Removing Elements From a List while Iterating through it std::list provides a member function erase() that accepts an iterator and deletes the element pointed by that Iterator. But it makes that iterator invalid i.e. we cannot use …
c++11 unordered_map : erase elements while iterating in a loop
In this article we will discuss how to erase multiple elements from an unordered_map based on some condition and while iterating. Erasing Multiple elements from unordered_map while iterating Suppose we have an unordered_map of string and integers as key value pairs i.e. Advertisements First : 1 Second : 2 Third : 3 Fourth :  4 Fifth : 5 …
c++11 unordered_map : erase elements while iterating in a loopRead More
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 Remove elements from HashMap while Iterating
In this article we will discuss different ways to remove elements from HashMap while Iterating. Let’s create a HashMap of String as Key and Integer as value and add some elements into it i.e. Advertisements // Create a HashMap of string and int HashMap<String, Integer> wordFreqMap = new HashMap<>(); // Add elements in Map wordFreqMap.put(“this”, …
Java : How to Remove elements from HashMap while IteratingRead More
Erase elements from a Set while Iterating in C++ & Generic erase_if()
In this article we will discuss how to erase elements from a set while iterating over it. Erasing elements from std::set while Iterating std::set provides a member function erase() that accepts an iterator as an argument and deletes it from the set i.e. iterator erase (const_iterator position); But it makes the passed iterator invalid. From …
Erase elements from a Set while Iterating in C++ & Generic erase_if()Read More
Python : How to Remove multiple keys from Dictionary while Iterating ?
In this article we will discuss how to remove multiple key / value pairs from dictionary while iterating. Suppose we have a dictionary of string and int i.e. Advertisements # Dictionary of strings wordFreqDic = { “Hello”: 51, “at” : 23 , “test” : 33, “here” : 63, “start” : 13 } Now we want …
Python : How to Remove multiple keys from Dictionary while Iterating ?Read More
Python: Remove elements from a list while iterating
This article will discuss different ways to delete elements from a list while iterating over it. Table of Contents Remove elements from list in for loop Remove elements from a list while iterating using list comprehension Remove elements from a list while iterating using filter() function Summary Remove elements from list in for loop Suppose …
Python: Remove elements from a list while iteratingRead More
Add element to list while iterating in Python
This tutorial will discuss about unique ways to append elements to list while iterating in Python. Table Of Contents Add elements to list while looping through it Add elements to list using for-loop Summary Add elements to list while looping through it Suppose we have a list of strings, and we want to add elements …