Server Side Programming Articles

Page 58 of 2109

Python - Find Minimum Pair Sum in list

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

The Minimum pair sum is defined by finding the smallest possible sum of two numbers taken from a given list. This concept is useful in optimization problems where you need to minimize costs, distances, or time for operations. Python provides several approaches to solve this using built-in functions like sort(), combinations(), and float(). Using Nested for Loop This approach uses nested loops to iterate through all possible pairs and track the minimum sum ? def min_pair(nums): min_sum = float('inf') min_pair = () ...

Read More

Python - Find Index Containing String in List

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

When working with mixed-type lists in Python, you often need to find the indices containing strings. This is useful for text parsing, pattern matching, and extracting specific information from data structures. Here's an example scenario: my_list = [108, 'Safari', 'Skybags', 20, 60, 'Aristocrat', 78, 'Raj'] print("Original list:", my_list) Original list: [108, 'Safari', 'Skybags', 20, 60, 'Aristocrat', 78, 'Raj'] The goal is to find indices 1, 2, 5, 7 where strings are located in this mixed list. Using for loop with type() function The most straightforward approach uses a for loop ...

Read More

Find the Index of Maximum Item in a List using Python

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

In Python, finding the index of the maximum item in a list is a common task. Python provides several built-in functions like max(), index(), and enumerate() that can be used to find the index of the maximum item in a list. For example, given the list [61, 12, 4, 5, 89, 7], the maximum value is 89 at index 4. Using index() with max() The simplest approach combines max() to find the maximum value and index() to find its position ? numbers = [61, 12, 4, 5, 89, 7] max_index = numbers.index(max(numbers)) print(f"Maximum value: {max(numbers)}") ...

Read More

Python - Inter Matrix Grouping

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 27-Mar-2026 222 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 628 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
Showing 571–580 of 21,090 articles
« Prev 1 56 57 58 59 60 2109 Next »
Advertisements