Server Side Programming Articles - Page 1778 of 2650

Combining tuples in list of tuples in Python

Pradeep Elance
Updated on 20-May-2020 10:20:36

618 Views

For data analysis, we sometimes take a combination of data structures available in python. A list can contain tuples as its elements. In this article we will see how we can combine each element of a tuple with another given element and produce a list tuple combination.With for loopIn the below approach we create for loops that will create a pair of elements by taking each element of the tuple and looping through the element in the list.Example Live DemoAlist = [([2, 8, 9], 'Mon'), ([7, 5, 6], 'Wed')] # Given list of tuple print("List of tuples : ", Alist) # ... Read More

Checking triangular inequality on list of lists in Python

Pradeep Elance
Updated on 20-May-2020 10:15:50

348 Views

The sum of two sides of a triangle is always greater than the third side. This is called triangle inequality. Python list of lists we will identify those sublists where the triangle inequality holds good.With for and >We will first get all the sublists sorted. Then for each sublist we will check if the if the sum of first two elements is greater than the third element.Example Live DemoAlist = [[3, 8, 3], [9, 8, 6]] # Sorting sublist of list of list for x in Alist:    x.sort() # Check for triangular inequality for e in Alist:    if e[0] ... Read More

Checking if starting digits are similar in list in Python

Pradeep Elance
Updated on 20-May-2020 10:09:50

371 Views

Sometimes in a given Python list we may be interested only in the first digit of each element in the list. In this article we will check if the first digit of all the elements in a list are same or not.With set and mapSet in Python does not allow any duplicate values in it. So we take the first digit of every element and put it in a set. If all the digits are same then the length of the set will be only 1 has no duplicates allowed.Example Live DemoAlist = [63, 652, 611, 60] # Given list print("Given ... Read More

Check whether a string is valid JSON or not in Python

Pradeep Elance
Updated on 20-May-2020 10:04:16

2K+ Views

JSON is a type of text format use to exchange data easily between various computer programs. It has a specific format which Python can validate. In this article we will consider a string and using JSON module we will validate if the string represents a valid JSON format or not.Creating JSON ObjectThe json module has method called loads. It loads a valid json string to create a Json object. In this example we load the string and check that there is no error in loading the JSON object. If there is error we consider the JSON string as invalid.Example Live Demoimport ... Read More

Program to find smallest difference of angles of two parts of a given circle in C++

Revathi Satya
Updated on 22-May-2024 11:49:53

330 Views

In this article, we will find the smallest difference in angles between two parts of a given circle using the C++ programming language. Before proceeding to the code, let’s first understand how we can calculate the angles to find the smallest difference between them. We are given the angles of all the pieces of the circle in the array. We have to join the pieces in such a way that the angle difference between the two pieces is the least. Let's go through the input and output scenario for better understanding. Here, we declare an array contianing three different angles ... Read More

Program to find Smallest and Largest Word in a String in C++

Ayush Gupta
Updated on 17-Sep-2020 04:50:56

4K+ Views

In this problem, we are given string str. Our task is to create a program to find Smallest and Largest Word in a String in C++.Problem Description − Here, we have a string we need to find the word whose length is maximum and minimum out of all words in the string. The word is separated using white spaces or null(\0) characters.Let’s take an example to understand the problemInputstr = “Learn Programming at TutorialsPoint”Outputsmallest word = at largest word = TutorialspointSolution ApproachTo find the smallest and largest word, we will find the length of each word by using two indexes, ... Read More

Program to find slope of a line in C++

Revathi Satya
Updated on 22-May-2024 11:48:48

2K+ Views

In this article, we will learn how to find the Slope of a line using a program. But before we proceed into the program, let's first understand what the Slope of a line represents in mathematics and how to compute it using its mathematics formula in C++. In mathematics, the Slope of a line is a numerical value that measures the line’s steepness and direction. It indicates the rate at which the line ups or down as you move along it from left to right (or horizontally). Generally, it is denoted by the letter "m". In mathematics, the steepness refers to the slope or gradient of a line. In terms of mathematical, ... Read More

Program to find size of Doubly Linked List in C++

Ayush Gupta
Updated on 17-Sep-2020 04:57:41

620 Views

In this problem, we are given a doubly linked list. Our task is to create a program to find size of Doubly Linked List in C++.Doubly Linked List is a special type of Linked list in which navigation is possible in both ways, either forward and backward easily as compared to Single Linked List. The following are the important terms to understand the concept of doubly linked lists.Link − Each link of a linked list can store a data called an element.Next − Each link of a linked list contains a link to the next link called Next.Prev − Each ... Read More

Program to find second most frequent character in C++

Ayush Gupta
Updated on 17-Sep-2020 05:00:42

860 Views

In this problem, we are given string str. Our task is to create a Program to find second most frequent character in C++.Let’s take an example to understand the problemInputstr = “abaacabcba”Output‘b’Solution ApproachTo find the character that is second most frequent in the string. We need to maintain a count array chatCount that is used to store the frequency of each character in the string. And then using the array we will find the character with max and secondMax frequency in the array. And display the second most frequent character.Program to illustrate the working of our solutionExample Live Demo#include #include ... Read More

Program to find root of an equations using secant method in C++

Ayush Gupta
Updated on 19-May-2020 11:51:15

1K+ Views

In this tutorial, we will be discussing a program to find the root of an equation using secant method.For this we will be provided with an equation. Our task is to find the roots of that equation using the iterative secant method.Example Live Demo#include using namespace std; float f(float x) {    float f = pow(x, 3) + x - 1;    return f; } void secant(float x1, float x2, float E) {    float n = 0, xm, x0, c;    if (f(x1) * f(x2) < 0) {       do {          //calculating the ... Read More

Advertisements