Found 26504 Articles for Server Side Programming

Delete elements with frequency atmost K in Python

Pradeep Elance
Updated on 04-May-2020 13:04:48

366 Views

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

Delete elements in range in Python

Pradeep Elance
Updated on 04-May-2020 13:03:02

822 Views

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

Optimal Division in C++

Arnab Chakraborty
Updated on 04-May-2020 13:06:53

322 Views

Suppose we have a list of positive integers; the adjacent integers will perform the float division. So for example, [2, 3, 4] -> 2 / 3 / 4. Now, we can add any number of parenthesis at any position to change the priority of these operations. We should find out how to add parenthesis to get the maximum result, we have to find the corresponding expression in string format. Our expression should NOT contain redundant parenthesis. So if the input is like [1000, 100, 10, 2], then the result will be “1000/(100/10/2)”.To solve this, we will follow these steps −n ... Read More

Decimal to binary list conversion in Python

Pradeep Elance
Updated on 04-May-2020 13:01:28

798 Views

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

Custom list split in Python

Pradeep Elance
Updated on 04-May-2020 13:00:43

501 Views

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

Minimum Time Difference in C++

Arnab Chakraborty
Updated on 04-May-2020 13:02:31

464 Views

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

Create list of numbers with given range in Python

Pradeep Elance
Updated on 04-May-2020 12:59:09

16K+ Views

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

Complex Number Multiplication in C++

Arnab Chakraborty
Updated on 04-May-2020 12:58:28

2K+ Views

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

Program to find N-th term of series 2, 12, 28, 50, 77, 112, 152, 198, …in C++

Ayush Gupta
Updated on 03-Oct-2020 09:39:55

96 Views

In this problem, we are given a number N. Our task is to create a program to find N-th term of series 2, 12, 28, 50, 77, 112, 152, 198, …in C++.Problem Description − To find the N-th term of the series.2, 12, 28, 50, 77, 112, 152, 198, ...N termsWe will find a general for the series.Let’s take an example to understand the problem, Input − N = 6Output − 112Solution Approach:Here, the series is increasing in parabolic form, so the general term will be a quadratic equation.So, the general formula for the series isTN = 3*(N*N) + N ... Read More

Program to find N-th term of series 0, 11, 28, 51, 79, 115, 156, 203, …In C++

Ayush Gupta
Updated on 03-Oct-2020 09:40:40

121 Views

In this problem, we are given a number N. Our task is to create a program to find N-th term of series 0, 11, 28, 51, 79, 115, 156, 203, … In C++.Problem Description − To find the Nth terms of the series −0, 11, 28, 51, 79, 115, 156, 203, … N-th term.Let’s take an example to understand the problem,Input − N = 5Output − 79Solution Approach:The general formula for nth term of the series is −Tn = 3*(N*N) + 2*N - 5Program to illustrate the working of our solution,#include using namespace std; int findNTerm(int N) { int nthTerm = ( (3*N*N) + 2*N - 5); return nthTerm; } int main() { int N = 9; cout

Advertisements