Tag: Elements
C++ : Different ways to insert elements in Set
In this article we will discuss different ways to insert an element in Set. Set provides 3 different overloaded version of insert() function to add element in set. Let’s discuss them one by one, Advertisements Inserting a Single element in Set and checking the result Set is an associative container and contains only unique elements, …
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 : Check if a list contains all the elements of another list
In this article we will discuss if a list contains all or any elements of another list. Suppose we have have two list i.e. Advertisements # List of string list1 = [‘Hi’ , ‘hello’, ‘at’, ‘this’, ‘there’, ‘from’] # List of string list2 = [‘there’ , ‘hello’, ‘Hi’] Check if list1 contains all elements of …
Python : Check if a list contains all the elements of another listRead More
Python : Check if all elements in a List are same or matches a condition
In this article we will dicuss different ways to check if all element in a given List are same or matches a condition. Suppose we have a list of string i.e. Advertisements # List of string listOfStrings = [‘Hello’] * 10 Now let’s use python all() function to check if all elements in the given …
Python : Check if all elements in a List are same or matches a conditionRead More
Python : How to remove multiple elements from list ?
In this article we will discuss different ways to remove multiple elements from list. Suppose we have a list of numbers i.e. # List of Numbers listOfnum = [12, 44, 56, 45, 34, 3, 4, 33, 44] Now we want to remove all the numbers from list, which are multiple of 3. Advertisements Remove multiple …
Python : How to remove multiple elements from list ?Read More
Python Tuple : Append , Insert , Modify & delete elements in Tuple
In this article we will discuss how to Append, Insert, Replace and Delete elements from a tuple in python. In Python, tuples are immutable i.e. once created we can not change its contents.  But sometimes we want to modify the existing tuple, in that case we need to create a new tuple with updated elements only …
Python Tuple : Append , Insert , Modify & delete elements in TupleRead More
NumPy – Select Elements By Condition
In this article we will discuss how to select elements or indices from a Numpy array based on multiple conditions. Similar to arithmetic operations when we apply any comparison operator to Numpy Array, then it will be applied to each element in the array and a new bool Numpy Array will be created with values …
Delete elements from a Numpy Array by value or conditions in Python
In this article we will discuss different ways to delete elements from a Numpy Array by matching value or based on multiple conditions. Remove all occurrences of an element with given value from numpy array Suppose we have a numpy array of numbers i.e. Advertisements # Create a numpy array from a list arr = …
Delete elements from a Numpy Array by value or conditions in PythonRead More
Python : Get number of elements in a list, lists of lists or nested list
In this article we will discuss different ways to count number of elements in a flat list, lists of lists or nested lists. Count elements in a flat list Suppose we have a list i.e. Advertisements # List of strings listOfElems = [‘Hello’, ‘Ok’, ‘is’, ‘Ok’, ‘test’, ‘this’, ‘is’, ‘a’, ‘test’] To count the elements …
Python : Get number of elements in a list, lists of lists or nested listRead More