Server Side Programming Articles

Page 100 of 2109

How to Get the Nth Word in a Given String using Python?

Rohan Singh
Rohan Singh
Updated on 27-Mar-2026 2K+ Views

Extracting specific words from a string is a common programming task. Python provides several approaches to get the Nth word from a string, including split() method, regular expressions, and custom delimiters. Using split() Method The simplest approach is splitting the string into words and accessing by index ? Syntax words = string.split() nth_word = words[n-1] # n is 1-based index Example def get_nth_word_split(string, n): words = string.split() if 1

Read More

Python - Leaf and Non-Leaf Nodes Dictionary

Asif Rahaman
Asif Rahaman
Updated on 27-Mar-2026 642 Views

Dictionary is an important data structure in Python which consists of key-value pairs. A nested dictionary can represent tree-like structures with nodes, where some nodes are leaf nodes (terminal nodes with no children) and others are non-leaf nodes (internal nodes with children). In this article, we will explore different approaches to identify and manipulate leaf and non-leaf nodes in Python dictionaries. What are Leaf and Non-Leaf Nodes? In tree-like dictionary structures, nodes are categorized based on whether they have children ? Leaf node: A node that does not have any child nodes. These are terminal nodes ...

Read More

Python - Lambda function to find the smaller value between two elements

Asif Rahaman
Asif Rahaman
Updated on 27-Mar-2026 534 Views

Lambda functions are anonymous functions in Python that provide a concise way to write small operations without defining a full function. In this article, we'll explore different methods to find the smaller value between two elements using lambda functions. Using Conditional Expression (if-else) The most straightforward approach uses Python's conditional expression within a lambda function ? # Direct lambda with conditional expression smaller = lambda a, b: a if a < b else b a = 45 b = 24 result = smaller(a, b) print(f"The smaller number between {a} and {b} is: {result}") ...

Read More

Python - Lambda Function to Check if a value is in a List

Asif Rahaman
Asif Rahaman
Updated on 27-Mar-2026 2K+ Views

Lambda functions in Python are nameless functions which are useful when we want to combine multiple expressions in a single line. The lambda function is convenient when we are sure that we won't be reusing the code anywhere else in the program. In this article we will understand how to check if a value exists in a list using the lambda function combined with various built-in methods. Using The filter() Method The filter() method in Python is a built-in function which creates new elements in the list depending upon certain filter conditions. It returns a filter object which ...

Read More

Python - Kth Valid String

Asif Rahaman
Asif Rahaman
Updated on 27-Mar-2026 222 Views

Finding the kth valid string is a common programming problem where we need to identify the kth element from a list that meets specific string validation criteria. In this article, we'll explore multiple approaches using iteration, filter methods, list comprehensions, and the Pandas library. Understanding The Problem Statement Given a list of elements and a value k, we need to find the kth valid string. A valid string typically contains only alphabetic characters and is not empty ? data = ["", "orange", "75", "apple", "123abc", "hello"] k = 2 # Valid strings: "orange", "apple", "hello" ...

Read More

Python - Kth Index Tuple List Mean

Asif Rahaman
Asif Rahaman
Updated on 27-Mar-2026 306 Views

Finding the mean of elements at the Kth index across multiple tuples is a common data analysis task in Python. Given a list of tuples and an index K, we calculate the average of all elements at position K across the tuples. Understanding The Problem Statement Our input contains a list of tuples and the value of K representing the index position. tuples_list = [(1, 2, 3), (4, 5, 6), (7, 8, 9)] k = 1 We need to find the mean of all elements at index K=1: From tuple (1, 2, 3): ...

Read More

Python - Kth digit Sum

Asif Rahaman
Asif Rahaman
Updated on 27-Mar-2026 306 Views

Finding the kth digit sum means calculating the sum of all digits at the kth position from each number in a list. This concept is useful in data validation, financial analysis, and pattern recognition. In this article, we will explore multiple approaches to find the kth digit sum using loops, list comprehensions, lambda functions, and libraries like NumPy and functools. Understanding The Problem Statement Suppose we have the following inputs − numbers = [123, 456, 789] k = 0 We need to find the kth digit sum. At index k=0, the digits are: 1 ...

Read More

Python - K Summation from Two lists

Asif Rahaman
Asif Rahaman
Updated on 27-Mar-2026 265 Views

K summation from two lists means finding all pairs of elements where one element comes from the first list, another from the second list, and their sum equals a target value k. Python offers several approaches to solve this problem efficiently. Using Brute Force Method The brute force approach checks every possible combination of elements from both lists ? def k_sum_naive(list1, list2, k): result = [] for num1 in list1: for num2 in list2: ...

Read More

Python - K Maximum Elements with Index in List

Asif Rahaman
Asif Rahaman
Updated on 27-Mar-2026 796 Views

Finding the k maximum elements with their indices from a list is a common programming task in Python. This article explores multiple approaches using built-in functions, libraries like NumPy and Pandas, and different algorithms to solve this problem efficiently. Using Brute Force Method The brute force approach repeatedly finds the maximum element, stores its value and index, then replaces it to find the next maximum ? def k_max_elements(data, k): data_copy = data.copy() # Work with copy to preserve original result = [] ...

Read More

Python - K Matrix Initialization

Asif Rahaman
Asif Rahaman
Updated on 27-Mar-2026 690 Views

Matrix is a popular data representation technique in mathematics, machine modeling, etc. They are designed to deal with linear functions. Matrix initialization is a process to fill up the elements (rows and columns) of the matrix with either random or some predetermined values. After initialization there should be no undefined entries in the matrix. Initializing the matrix is one of the essential tasks in several fields, like competitive programming, machine and deep learning algorithms. In this article, we will learn how to initialize the matrix using various methods like loops, NumPy arrays, etc. Using Custom Logic with Lists ...

Read More
Showing 991–1000 of 21,090 articles
« Prev 1 98 99 100 101 102 2109 Next »
Advertisements