Tapas Kumar Ghosh

Tapas Kumar Ghosh

185 Articles Published

Articles by Tapas Kumar Ghosh

Page 4 of 19

Python - Inter Matrix Grouping

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 27-Mar-2026 225 Views

Inter Matrix Grouping is a technique where elements from two lists are grouped based on matching first elements. When matches are found, the first element becomes a dictionary key, and the remaining elements form grouped values. Python provides several built-in functions like setdefault(), defaultdict(), and append() to implement this efficiently. Understanding the Concept Let's understand this with an example: list1 = [[1, 2], [3, 4], [4, 5], [5, 6]] list2 = [[5, 60], [1, 22], [4, 59], [3, 14]] # Result: {1: [2, 22], 3: [4, 14], 4: [5, 59], 5: [6, 60]} ...

Read More

How to Iterate through a List without using the Increment Variable in Python

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 27-Mar-2026 347 Views

Iteration allows you to process each element in a list without manually managing an increment variable. Python provides several built-in functions and techniques like enumerate(), map(), list comprehension, and direct iteration that eliminate the need for manual counter variables. Using Direct Iteration (Simple For Loop) The most straightforward way is to iterate directly over list elements ? fruits = ["apple", "banana", "orange", "grape"] for fruit in fruits: print(fruit) apple banana orange grape Using enumerate() Function When you need both index and value, enumerate() provides automatic ...

Read More

How to Initialize an Empty Array of given Length using Python

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 27-Mar-2026 16K+ Views

An empty array consists of either null values or no elements. Empty arrays are useful when you need to initialize storage before populating it with data. Python provides several methods to create empty arrays of a given length using built-in functions and libraries. Using Multiplication (*) Operator The multiplication operator repeats elements to create an array of specified length ? length = 5 arr = [None] * length print("Empty array using multiplication operator:") print(arr) print("Length:", len(arr)) Empty array using multiplication operator: [None, None, None, None, None] Length: 5 Using NumPy empty() ...

Read More

Initialize a Dictionary with Custom Value list in Python

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 27-Mar-2026 632 Views

Initializing a dictionary with custom value lists means creating a dictionary where each key maps to a list containing specific values. This approach is useful when you need to group multiple values under each key or when you want each value to be in list format for further manipulation. Syntax Overview Python provides several built-in functions to initialize dictionaries with custom value lists: range() - Returns a sequence of numbers len() - Returns the length of an object zip() - Combines multiple iterables dict() - Creates a dictionary enumerate() - Iterates with index tracking ...

Read More

Iterating through a range of dates in Python

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 27-Mar-2026 8K+ Views

Iterating through a range of dates is a common task in Python applications. Python's datetime module provides several functions like date(), timedelta(), and built-in functions like range() to accomplish this efficiently. For example, if we want to iterate from 2023-06-26 to 2023-06-30, we would get: 2023-06-26 2023-06-27 2023-06-28 2023-06-29 2023-06-30 Key Functions datetime.date() − Creates date objects representing calendar dates. timedelta() − Represents a duration, the difference between two dates or times. ...

Read More

How to show or hide labels in Pygal

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 27-Mar-2026 283 Views

Pygal is a Python data visualization library that creates interactive SVG graphs. It provides various chart types like line charts, bar charts, pie charts, and more. This article demonstrates how to work with labels in Pygal charts using functions like x_labels, add(), and render_to_file(). Installation First, install Pygal using pip ? pip install pygal Key Functions for Labels x_labels Sets labels for the horizontal axis of the chart. add() Adds data series to the chart with optional labels for each series. render_to_file() Saves the chart as an SVG ...

Read More

Initialize Dictionary keys with Matrix in Python

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 27-Mar-2026 419 Views

Dictionary keys can be initialized with matrix values using several Python methods. A matrix in Python is typically represented as a list of lists, where each inner list represents a row or column of data. What is Matrix Initialization in Dictionaries? Matrix initialization means creating dictionary keys where each value is a matrix structure (list of lists). This is useful for storing multi-dimensional data organized by categories. Using While Loop and append() Method This method iterates through dictionary keys and appends empty lists to create matrix structures ? # Initialize dictionary with empty lists ...

Read More

Incremental List Extension in Python

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 27-Mar-2026 511 Views

Incremental list extension creates a new list where each element from the original list is combined with a series of incremental values. This pattern is useful for generating mathematical sequences, creating test data, or expanding datasets with calculated variations. Understanding the Pattern The incremental extension follows this formula: for each element, add values [0, E, E², E³, ...] where E is the extension factor and the sequence length is determined by range n. Method 1: Using Nested List Comprehension This approach uses two list comprehensions to generate the extension values and combine them with original elements ...

Read More

Python - Incremental Sublist Sum

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 27-Mar-2026 341 Views

An incremental sublist sum (also known as cumulative sum) calculates running totals of elements in a list. Each position contains the sum of all elements from the start up to that position. For example, given the list [10, 20, 30, 40, 50]: Index 0: 10 Index 1: 10 + 20 = 30 Index 2: 10 + 20 + 30 = 60 Index 3: 10 + 20 + 30 + 40 = 100 Index 4: 10 + 20 + 30 + 40 + 50 = 150 The result is [10, 30, 60, 100, 150]. Using a ...

Read More

Conversion of Integer String to list in Python

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 27-Mar-2026 746 Views

Converting an integer string to a list is a common task in Python programming. An integer string contains numeric characters (like "123" or "1 2 3"), and we want to transform it into a list of integers. Python provides several built-in methods to accomplish this conversion efficiently. Using map() and split() Functions The most common approach uses map() and split() to convert space-separated integers ? int_str = "1 2 3 4 5" result = list(map(int, int_str.split())) print("Converted list:", result) Converted list: [1, 2, 3, 4, 5] Using List Comprehension For ...

Read More
Showing 31–40 of 185 articles
« Prev 1 2 3 4 5 6 19 Next »
Advertisements