Articles on Trending Technologies

Technical articles with clear explanations and examples

Python program to find better divisor of a number

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 496 Views

Finding the "better divisor" of a number involves comparing divisors based on their digit sum. A divisor with a higher digit sum is considered better, and if digit sums are equal, the smaller number wins. Problem Definition Given a number n, we need to find the best divisor based on these criteria ? The divisor with the highest sum of digits is better If digit sums are equal, the smaller divisor is better Example For n = 180, the divisors are [1, 2, 3, 4, 5, 6, 9, 10, 12, 15, 18, 20, ...

Read More

Python program to get average heights of distinct entries

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 747 Views

Suppose we have a set of heights where there may be some duplicate entries. We need to find the average of distinct entries from these heights. So, if the input is like heights = [96, 25, 83, 96, 33, 83, 24, 25], then the output will be 52.2 because the unique elements are [96, 25, 83, 33, 24], so sum is 96 + 25 + 83 + 33 + 24 = 261, average is 261/5 = 52.2. Algorithm To solve this problem, we will follow these steps ? h_set := a set from heights to ...

Read More

Program to find only even indexed elements from list in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 2K+ Views

In Python, we can extract elements at specific positions from a list. To find only even indexed elements (elements at positions 0, 2, 4, etc.), we can use list slicing techniques. So, if the input is like nums = [5, 7, 6, 4, 6, 9, 3, 6, 2], then the output will be [5, 6, 6, 3, 2] (elements at indices 0, 2, 4, 6, 8). Understanding Even vs Odd Indices Let's first clarify the index positions in our example list ? nums = [5, 7, 6, 4, 6, 9, 3, 6, 2] # ...

Read More

Python program to convert complex number to polar coordinate values

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 478 Views

Converting a complex number to polar coordinates involves finding the magnitude (radius) and phase angle. For a complex number x + yj, the radius is sqrt(x² + y²) and the angle is measured counter-clockwise from the positive x-axis. Python's cmath module provides built-in functions: abs() for magnitude and phase() for the angle in radians. Syntax import cmath magnitude = abs(complex_number) angle = cmath.phase(complex_number) Example Let's convert the complex number 2+5j to polar coordinates ? import cmath def convert_to_polar(c): return (abs(c), cmath.phase(c)) c = 2+5j ...

Read More

Python program to get all permutations of size r of a string

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 532 Views

Python's itertools.permutations() function generates all permutations of a specified length from a string. A permutation is an arrangement of elements where order matters. Syntax itertools.permutations(iterable, r) Parameters: iterable − The input string or sequence r − Length of each permutation (optional, defaults to full length) Example Let's generate all permutations of size 3 from the string "HELLO" ? from itertools import permutations def solve(s, r): vals = list(permutations(s, r)) result = [] for x in vals: ...

Read More

PHP – Return an array of all supported encodings with mb_list_encodings()

Urmila Samariya
Urmila Samariya
Updated on 26-Mar-2026 379 Views

Looking at this article, I notice there's a topic mismatch - it's about PHP but the instructions are for Python articles. However, I'll improve the PHP article following the general improvement guidelines. The mb_list_encodings() function in PHP returns an array of all supported character encodings available in the multibyte string extension. This function is part of PHP's mbstring extension and is available in PHP 5.0.0 and higher versions. Syntax array mb_list_encodings() Parameters The mb_list_encodings() function takes no parameters. Return Value This function returns a numerically indexed array containing the names of ...

Read More

Python program to find how much money will be earned by selling shoes

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 470 Views

Suppose in a shoe shop there are n different shoes with different sizes present in an array called shoes and another list of pairs for m customers called demand is given, where demand[i] contains (shoe_size, money). A customer with demand i wants a shoe of size shoe_size and can pay the given amount of money. We need to find how much money the shopkeeper can earn by selling these shoes. Example If the input is shoes = [2, 3, 4, 5, 6, 8, 7, 6, 5, 18] and demand = [(6, 55), (6, 45), (6, 55), (4, 40), ...

Read More

Python program to find Cartesian product of two lists

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 6K+ Views

The Cartesian product of two lists creates all possible ordered pairs by combining each element from the first list with every element from the second list. Python provides multiple approaches to find the Cartesian product using itertools.product(), nested loops, or list comprehensions. Problem Understanding If we have two lists like [a, b] and [c, d], the Cartesian product will be [(a, c), (a, d), (b, c), (b, d)]. For input lists l1 = [1, 5, 6] and l2 = [1, 2, 9], the output should be all combinations of elements from both lists. Using itertools.product() The ...

Read More

Python program to capitalize each word\'s first letter

Akshitha Mote
Akshitha Mote
Updated on 26-Mar-2026 2K+ Views

Let's understand the problem statement: we need to convert a given string to a title case, which involves capitalizing the first letter of each word while converting the remaining letters to lowercase. The following are the various ways to capitalize each word's first letter in a string ? Using title() method Using capitalize() method Using upper() method Importing string module Importing regex module Capitalizing a String in a File Using the title() ...

Read More

Python program to print rangoli pattern using alphabets

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 5K+ Views

A rangoli pattern is a diamond-shaped pattern that uses alphabets arranged symmetrically. Given a number n, we create an alphabet rangoli of size n where alphabets start from 'a' and go up to the nth letter of the alphabet. Understanding the Pattern For n = 5, the rangoli pattern looks like this: --------e-------- ------e-d-e------ ----e-d-c-d-e---- --e-d-c-b-c-d-e-- e-d-c-b-a-b-c-d-e --e-d-c-b-c-d-e-- ----e-d-c-d-e---- ------e-d-e------ --------e-------- The pattern has the following characteristics: Each row is symmetric with dashes for spacing The middle row contains all alphabets from 'a' to the nth letter Upper and lower halves mirror ...

Read More
Showing 1–10 of 61,303 articles
« Prev 1 2 3 4 5 6131 Next »
Advertisements