Found 26504 Articles for Server Side Programming

How to Find The Largest Or Smallest Items in Python?

Kiran P
Updated on 10-Nov-2020 05:10:16

416 Views

This article is aimed at developers who want to find the largest or smallest items with Python. I will show a few methods touse and will conclude the best method for you.Method – 1: Slice approach on a ListIf you are simply trying to find the single smallest or largest item i.e N = 1, it is faster to use min() and max().Let us begin by generating some random integers.import random # Create a random list of integers random_list = random.sample(range(1, 10), 9) random_listOutput[2, 4, 5, 1, 7, 9, 6, 8, 3] FINDING THE SMALLEST & LARGEST ITEM (N=1) # ... Read More

How to Identify Most Frequently Occurring Items in a Sequence with Python?

Kiran P
Updated on 10-Nov-2020 05:03:25

300 Views

ProblemYou need to identify the most frequently occurring items in a sequence.SolutionWe can use counter to keep track of the items in a sequence.What is a Counter ?The “Counter” is a mapping that holds an integer count for each key. Updating an existing key adds to its count. This Objectis used for counting the instances of hashable objects or as a multiset.The “Counter” is one of your best friends when you are performing data analysis.This object has been present in Python for quite some time, and so for a lot of you, this will be a quick review.We will start ... Read More

How to split strings on multiple delimiters with Python?

SaiKrishna Tavva
Updated on 09-Oct-2024 14:02:07

2K+ Views

Depending on the flexibility and complexity required, we can split a string on multiple delimiters in several ways such as using Python's re.split() method, which is a combination of various string methods. Some of the commonly used approaches to split strings on multiple delimiters. str.replace() and str.split() re.split() Method translate() ... Read More

Count the pairs of vowels in the given string in C++

Sunidhi Bansal
Updated on 02-Nov-2020 06:20:11

366 Views

We are given with a string of characters and the task is to calculate the count of pairs having both the elements as vowels. As we know there are five vowels in English alphabet i.e. a, i, e, o, u and other characters are known as Consonants.Input − string str = "tutorials point”Output − Count the pairs of vowels in the given string are: 2Explanation − From the given string we can form pairs as (t, u), (u, t), (t, o), (o, r), (r, i), (i, a), (a, l), (l, s), (s, p), (p, o), (o, i), (i, n) and ... Read More

Count the number of elements in an array which are divisible by k in C++

Sunidhi Bansal
Updated on 02-Nov-2020 06:18:19

1K+ Views

We are given with an array of positive integer numbers and an integer variable k. The task is to calculate the count of the number of elements in an array which is divisible by the given value k.Input − int arr[] = {4, 2, 6, 1, 3, 8, 10, 9}, k = 2Output − Count the number of elements in an array which are divisible by 2 are − 5Explanation − we will divide the elements in an array by a value k and check whether the reminder is 0 or not. So, 4 is divisible by 2, 2 is ... Read More

Count of character pairs at same distance as in English alphabets in C++

Sunidhi Bansal
Updated on 02-Nov-2020 06:16:00

173 Views

We are given a string of characters and the task is to calculate the count of character pairs having pairs at the same distance as we have in english alphabets.Input − string str = ‘Tutorials Point’Output − Count of character pairs at same distance as in English alphabets are: 5Explanation − The character pairs with same distance as in english alphabets are (u, t), (u, r), (t, r), (i, o) and (s, n). So in total there are 5 pairs.Input − string str = ‘Learning is the best habit’Output − Count of character pairs at same distance as in English ... Read More

Count of numbers having only 1 set bit in the range [0, n] in C++

Sunidhi Bansal
Updated on 02-Nov-2020 06:14:40

259 Views

We are given a number and the task is to calculate the count of numbers from the range 0 till the given number let’s say, num having exactly one set bitSet bits in a binary number is represented by 1. Whenever we calculate the binary number of an integer value then it is formed as the combination of 0’s and 1’s. So, the digit 1 is known as set bit in the terms of the computer.Input − int num = 15Output − Count of numbers having only 1 set bit in the range [0, 15] are − 4Explanation − The ... Read More

Count of matrices (of different orders) with given number of elements in C++

Sunidhi Bansal
Updated on 02-Nov-2020 06:12:30

268 Views

We are given the total number of elements and the task is to calculate the total number of matrices with different orders that can be formed with the given data. A matrix has an order mxn where m are the number of rows and n are the number of columns.Input − int numbers = 6Output −Count of matrices of different orders that can be formed with the given number of elements are: 4Explanation − we are given with the total number of elements that a matrix of any order can contain which is 6. So the possible matrix order with ... Read More

Count of elements of an array present in every row of NxM matrix in C++

Sunidhi Bansal
Updated on 02-Nov-2020 06:11:21

814 Views

We are given an array of integer type elements and a matrix or 2-D array of given row and column size and the task is to calculate the count of elements of an array that are present in each row of a matrix.Input int arr = { 2, 4, 6} and int matrix[row][col] = { { 2, 4, 6 }, {3, 4, 6}, {6, 2, 1}}Output Elements of array in row 1 are: 3 Elements of array in row 2 are: 2 Elements of array in row 3 are: 2Explanation we are having array containing 2, 4 and 6 as elements and now ... Read More

Count pairs from two linked lists whose product is equal to a given value in C++

Sunidhi Bansal
Updated on 02-Nov-2020 06:08:56

126 Views

We are given with two linked lists and the task is to form the pairs using the integer elements of linked lists such that their product is equal to a given value which is let’s say, k. A linked list is a sequence of data structures, which are connected together via links.Input vector v_1 = {5, 7, 8, 10, 11}, . vector v_2 = {6, 4, 3, 2, 0} , int k = 20Output Count of pairs from two linked lists whose product is equal to a given value k are: 2Explanation The pairs which can be formed using the given linked lists ... Read More

Advertisements