Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Server Side Programming Articles
Page 32 of 2109
Print Python list elements in circular range
The list data structure in Python holds elements of different data types like integers, strings, or float numbers. Printing list elements in a circular range means starting from any index and wrapping around to the beginning when reaching the end, creating sublists of a specified length. What is Circular Range? In a circular range, if you have a list [5, 6, 7, 8] and want sublists of length 4 starting from each position, you get: Starting from index 0: [5, 6, 7, 8] Starting from index 1: [6, 7, 8, 5] (wraps around) Starting from index ...
Read MorePython – Program that matches a word containing ‘g’ followed by one or more e’s using regex
Regular expressions (regex) in Python provide powerful pattern matching capabilities. In this tutorial, we'll learn how to match words containing 'g' followed by one or more 'e' characters using different regex methods. Understanding the Regex Pattern The pattern r'\bge+\w*\b' breaks down as follows ? \b − Word boundary to match complete words g − Literal character 'g' e+ − One or more 'e' characters \w* − Zero or more word characters (optional) \b − Word boundary at the end Method 1: Using findall() Function The findall() method returns all non-overlapping matches as a ...
Read MorePrint diagonals of 2D list in Python
Python provides powerful features for working with two-dimensional data structures. One common task is extracting diagonal elements from a 2D list (matrix). This article demonstrates how to print both major and minor diagonals using simple iteration methods. Understanding Matrix Diagonals Before extracting diagonals, let's understand the concept with a visual representation: ...
Read MorePython - Print alphabets till N
Python provides several ways to print alphabets up to a specified position N. When N is 5, for example, the program prints the first 5 letters: a, b, c, d, e. This is useful for creating patterns, educational programs, and understanding ASCII character manipulation. Understanding the Problem In the English alphabet, there are 26 letters total. When we specify N=5, we want to print the first 5 letters (a through e). The position N determines how many alphabets to display from the beginning. Using the String Module The string module provides predefined constants like ascii_lowercase and ...
Read MorePython – Product of squares in list
The product of squares in a list means calculating the square of each element first, then multiplying all the squared values together. Python provides multiple approaches to solve this problem efficiently. Understanding the Problem Given a list like [9, -4, 8, -1], we need to ? Square each element: 9² = 81, (-4)² = 16, 8² = 64, (-1)² = 1 Multiply all squares: 81 × 16 × 64 × 1 = 82944 Method 1: Using Iteration Iterate through each element, square it, and multiply with the running product ? # ...
Read MorePython – Product of prefix in list
Finding the product of prefix in a list means calculating cumulative products where each position contains the product of all elements from the start up to that position. Python offers several approaches to accomplish this task efficiently. What is Product of Prefix? Given a list, the product of prefix transforms it so that each element becomes the product of all preceding elements including itself. For example: Original List [5, 6, 7, 8] Product of Prefix [5, 30, 210, 1680] The calculation works as follows: Position 0: 5 = ...
Read MorePython – Prefix sum Subarray till False value
In Python, a prefix sum subarray till false value means computing cumulative sums of elements until encountering a "falsy" value (like 0, False, None, empty list, etc.). This technique is useful for conditional cumulative calculations where processing should stop at certain conditions. Understanding Prefix Sum with False Values Consider an array where we want to calculate prefix sums but stop when we encounter a false value ? Index 0 1 2 3 4 5 6 Value 2 10 4 3 0 10 -2 Prefix Sum 2 12 16 19 Stop - ...
Read MorePython – Priority key assignment in dictionary
Priority key assignment in Python dictionaries allows you to process dictionary elements in a specific order based on their importance. This technique is particularly useful when working with data that has different priority levels. What is Priority Key Assignment? Priority key assignment means defining which dictionary keys should be processed first based on their importance. Instead of processing keys randomly, you can establish a priority order to ensure critical data is handled before less important data. Basic Dictionary Syntax # Basic dictionary structure sample_dict = {'hello': 'all', 'welcome': 897} print(sample_dict) {'hello': 'all', ...
Read MorePython – Print list after removing element at given index
Python lists are mutable data structures that allow you to store elements of different data types. Sometimes you need to remove elements at specific positions. This article demonstrates three methods to print a list after removing elements at given indices. Original List: 0 1 2 3 4 ...
Read MorePython – Product of kth column in list of lists
Python lists can contain sublists, creating a two-dimensional structure. Sometimes you need to calculate the product of elements in a specific column across all rows. This article demonstrates how to find the product of the kth column in a list of lists using different approaches. For example, consider this 3x3 matrix: matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] # To get product of column 2 (index 2): 3 * 6 * ...
Read More