Found 10784 Articles for Python

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

Asif Rahaman
Updated on 18-Jul-2023 14:41:34

223 Views

Lambda functions are popular functions in Python which have no name. They are designed to help us when we need to apply any small operation but we know we won't be reusing the code elsewhere. In this article we will learn how to find the smaller value between two elements using the lambda function. We will explore several methods like min, sorted etc along with the lambda function to perform the same. Using The if else Statement The if else statement is called the conditional operator in Python. It gives us the ability to make certain decisions based on certain ... Read More

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

Asif Rahaman
Updated on 18-Jul-2023 14:39:21

1K+ 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. If however the expression is long we may want to switch to regular functions instead. In this article we will understand how to check if a value exists in a list using the lambda function. Using The filter Method The filter method in Python is a built−in function which creates new elements in the list depending upon certain ... Read More

Python - Kth Valid String

Asif Rahaman
Updated on 18-Jul-2023 14:32:42

64 Views

Strings are important data types in any programming language. They are sequences of characters. Finding kth valid String is a programming technique in which we need to find the kth element out of a list of elements which is a valid String. In this article we will understand several methods like brute force, using list comprehensions and enumerate objects, filter method etc. We will also see how to use the Pandas library to deal with the same. Understanding The Problem Statement We will have list and the value of k as the input: list: ["", "orange", "75", "apple"] k: ... Read More

Python - Kth Index Tuple List Mean

Asif Rahaman
Updated on 18-Jul-2023 14:29:38

95 Views

Finding the Kth index tuple list is an important programming concept in Python. The problem statement is that we need to find the mean of all the elements present at the kth index of the tuple elements. The tuples would be aggregated into a list data type. Throughout this article, we will adopt different approaches like using a while loop, list comprehension, and libraries like Pandas, NumPy, Statistics, etc. Understanding The Problem Statement Our input should contain a list of tuples and the value of k. list: [(1, 2, 3), (4, 5, 6), (7, 8, 9)] k: ... Read More

Python - Kth digit Sum

Asif Rahaman
Updated on 18-Jul-2023 14:27:26

89 Views

Finding the kth digit sum means we must find the sum of all the digits at the kth index of a list of numbers. This is an important programming concept, and we use this in data validation, financial analysis, etc. In this article, we will explore how to find the kth digit sum with the help of several custom methods like loops, list comprehensions, lambda, map functions, etc. We will also use libraries like Numpy and Functool to achieve the same. Understanding The Problem Statement Suppose we have the following inputs: list: [12, 73, 64] k=0 ... Read More

Python - K Summation from Two lists

Asif Rahaman
Updated on 18-Jul-2023 14:25:52

85 Views

List is an important data type in Python that can hold sequence of either homogeneous or heterogeneous data types. They are mutable. Finding the k summation from two lists means we need to find the combinations of the elements of two lists, which can add up to make the sum exactly equal to k. In this article, we will first explore the brute force method. Next, we would look into several optimized algorithms like two pointer approach, hashing algorithms, list comprehensions, etc. Using The Brute Force Method Brute force is the simplest approach. We write the logic without considering ... Read More

Python - K Maximum Elements with Index in List

Asif Rahaman
Updated on 18-Jul-2023 14:24:13

304 Views

The list is a popular mutable data type in Python that can hold heterogeneous data. We can access the list elements by using a process called indexing. The indexing means the distance of any element from the first element; hence it starts from 0. This article will explore how to find the k maximum elements and index number. We will achieve this through several methods like brute force, recursion, heapq module, Numpy library, enumerate functions, etc. We will also explore the time and space complexity of the algorithms used. Using The Brute Force Method Brute force is the simplest ... Read More

Python - K Matrix Initialization

Asif Rahaman
Updated on 18-Jul-2023 14:21:30

212 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. We would also explore different types of ... Read More

Python - K length decimal Places

Asif Rahaman
Updated on 18-Jul-2023 14:15:00

116 Views

In computer science we define decimal numbers to be the numbers which utilize base10 notations. For example 12, 4, 5.7, 99 are decimal numbers because they utilize base 10 notation. We can define the length of a decimal number as the number of digits present in the decimal number. More precisely, the number of significant figures present in the decimal number includes both digits after and before the decimal parts. This article will explore several methods to find the k−length decimal places like the round method, String formatting, Global precisions, etc. Using round Method One of the ... Read More

Python - K length consecutive characters

Asif Rahaman
Updated on 18-Jul-2023 14:12:17

980 Views

Consecutive characters are those characters that appear one after the other. k length consecutive characters mean the same character appearing k times consecutively. In this article, we will adopt several methods to achieve it. We will start with brute force by using loop statements. Next, we will perform the same using regular expressions, sliding window techniques, etc. A sliding window is a better and optimized way to find the k-length consecutive characters. Numpy Library also offers us methods to adopt similar techniques. Using the Brute Force Method Brute force is a simple algorithm that we can think about without ... Read More

Advertisements