Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 26 of 377

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 479 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 534 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

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 472 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 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

Python program to print decimal octal hex and binary of first n numbers

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

Sometimes we need to display numbers in different formats: decimal, octal, hexadecimal, and binary. Python provides format specifiers to convert numbers into these representations with proper alignment. So, if the input is like n = 10, then the output will be ? 1 1 1 1 2 2 2 10 3 3 3 11 4 4 4 100 5 5 5 101 6 6 ...

Read More

Python program to print design door mat texture using characters

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

A door mat pattern is a decorative text design that creates a symmetric mat-like structure. In this pattern, we use hyphens (-), dots (.), and pipe symbols (|) to create a design with "WELCOME" in the center. The mat has dimensions n × m, where m is a multiple of n. Understanding the Pattern The door mat follows this structure: Top half: Expanding pattern from 1 to n-1 (odd numbers only) Middle: "WELCOME" text surrounded by hyphens Bottom half: Mirror of the top half in reverse order Each row contains: Left padding of ...

Read More

Python program to wrap a text into paragraph with width w

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

Text wrapping is a common task when formatting output for display or printing. Python's textwrap module provides the fill() function to wrap text into paragraphs with a specified width. Syntax textwrap.fill(text, width=70, **kwargs) Parameters The fill() function accepts the following parameters: text − The string to be wrapped width − Maximum line width (default is 70) break_long_words − Break words longer than width (default True) break_on_hyphens − Break on hyphens (default True) Basic Text Wrapping Let's wrap a text string with width 9 ? import textwrap ...

Read More

Python program to show diamond pattern with 2n-1 lines

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

A diamond pattern is a symmetric arrangement of asterisks that expands from one star to n stars, then contracts back to one star. The pattern consists of 2n-1 lines total, with the widest part containing n asterisks. Understanding the Pattern For n = 5, the diamond pattern looks like ? * * * * * * * * * * * * * * * * * * * * * * * * * ...

Read More
Showing 251–260 of 3,768 articles
« Prev 1 24 25 26 27 28 377 Next »
Advertisements