While manipulating data from lists we may come across scenario where we have selectively remove elements form the list based on their frequency. In this article we will explore how to remove all elements from a list whose frequency is less than equal to 2. You can also change the value 2 to any number in the programs.With countThe count methods keep the count of each element in the list. So we use it with a for loop and put a condition to only keep the elements whose count is greater than 2.Example Live DemolistA = ['Mon', 3, 'Tue', 'Mon', 9, ... Read More
Deleting a single element from a python is straight forward by using the index of the element and the del function. But there may be scenarios when we need to delete elements for a group of indices. This article explores the approaches to delete only those elements form the list which are specified in the index list.Using sort and delIn this approach we create a list containing the index values where deletion has to happen. The we sort and reverse them to preserve the original order of the elements of the list. Finally we apply the del function to the ... Read More
Suppose we have a list of 24-hour clock time points in "Hour:Minutes" format, we have to find the minimum minutes difference between any two time points in the list. So if the input is like [“12:30”, ”15:17”], so this will return 167.To solve this, we will follow these steps −Define an array called ok of size 24*60 + 1, and initially all are false.n := size of tpfor i in range 0 to n – 1hr := the hour part from the timemin := minute part of the stringtime := hr * 60 + minif ok[time] is true, then return ... Read More
Python being a versatile language can handle many requirements that comes up during the data processing. When we need to convert a decimal number to a binary number we can use the following python programs.Using formatWe can Use the letter in the formatter to indicate which number base: decimal, hex, octal, or binary we want our number to be formatted. In the below example we take the formatter as 0:0b then supply the integer to the format function which needs to get converted to binary.Example Live DemoDnum = 11 print("Given decimal : " + str(Dnum)) # Decimal to binary ... Read More
Data analytics throws complex scenarios where the data need to be wrangled to moved around. In this context let’s see how we can take a big list and split it into many sublists as per the requirement. In this article we will explore the approaches to achieve this.With zip and for loopIn this approach we use list dicing to get the elements from the point at which the splitting has to happen. Then we use zip and for loop to create the sublists using a for loop.Example Live DemoAlist = ['Mon', 'Tue', 'Wed', 6, 7, 'Thu', 'Fri', 11, 21, 4] ... Read More
Python can handle any requirement in data manipulation through its wide variety of libraries and methods. When we need to generate all the numbers between a pair of given numbers, we can use python’s inbuilt functions as well as some of the libraries. This article describes such approaches.Using rangeThe range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 ending at a specified number. We can of curse change the starting, ending as well as increment steps to suit our need.Example Live Demodef getnums(s, e, i): return list(range(s, e, i)) # Driver Code ... Read More
Suppose we have two strings that are representing complex numbers, we have to parse them and perform complex number multiplication, then return result as a string.So if the input is like “1+-1i” and “1+-1i”, then the result will be “0+-2i”.To solve this, we will follow these steps −aa := a pair of real and imaginary of first complex numberbb := a pair of real and imaginary of second complex numberx := aa.real * bb.real – aa.img*bb.imgy := aa.real * bb.img + aa.img*bb.realreturn the string as “x+yi”Let us see the following implementation to get better understanding −Example Live Demo#include using namespace ... Read More
In this tutorial, we will be discussing a program to find N-th term of series 1, 6, 17, 34, 56, 86, 121, 162, …For this, we will be provided with a number. Our task is to find the term for the given series at that particular position.Example Live Demo#include #include using namespace std; //calculating nth term of given series int nthTerm(int n) { return 3 * pow(n, 2) - 4 * n + 2; } int main() { int N = 4; cout
In this tutorial, we will be discussing a program to find N-th term of series 0, 10, 30, 60, 99, 150, 210, 280...For this, we will be provided with a number. Our task is to find the term for the given series at that particular position.Example Live Demo#include #include using namespace std; //calculating nth term of series int nthTerm(int n) { return 5 * pow(n, 2) - 5 * n; } int main() { int N = 4; cout
In this tutorial, we will be discussing a program to find N-th term of series 0, 7, 8, 33, 51, 75, 102, 133...For this, we will be provided with a number. Our task is to find the term for the given series at that particular position.Example Live Demo#include #include using namespace std; //calculating nth term of series int nthTerm(int n) { return 2 * pow(n, 2) + n - 3; } int main() { int N = 4; cout
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP