SaiKrishna Tavva

SaiKrishna Tavva

80 Articles Published

Articles by SaiKrishna Tavva

Page 2 of 8

How to have logarithmic bins in a Python histogram?

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 25-Mar-2026 6K+ Views

In Python, creating a logarithmic histogram involves using logarithmically spaced bins instead of linear ones. This is particularly useful when your data spans several orders of magnitude. We can achieve this using NumPy for generating logarithmic bins and matplotlib for plotting. Logarithmic bins are spaced exponentially rather than linearly, making them ideal for data that follows power-law distributions or spans wide ranges. Basic Example with Logarithmic Bins Let's create a simple histogram with logarithmic bins ? import matplotlib.pyplot as plt import numpy as np # Create sample data data = np.random.exponential(scale=2, size=1000) # ...

Read More

How to find the first date of a given year using Python?

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 25-Mar-2026 6K+ Views

The datetime module in Python can be used to find the first day of a given year. This datetime module is widely used for manipulating dates and times in various formats and calculations. Common approaches to find the first day of a given year using Python are as follows ? Datetime Module − Widely used library for manipulating dates and times in various ways. Calendar Module ...

Read More

Python Program to Implement Binary Search without Recursion

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 25-Mar-2026 5K+ Views

To implement binary search without recursion, the program uses an iterative approach with a while loop. Binary search is an efficient algorithm that finds a specific element in a sorted list by repeatedly dividing the search space in half. This method compares the target with the middle element of the current search range. If they match, the search is complete. If the target is smaller, it searches the left half; if larger, it searches the right half. This process continues until the element is found or the search space is exhausted. Algorithm Steps The iterative binary search ...

Read More

Rotate Matrix in Python

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 25-Mar-2026 7K+ Views

Rotating a matrix in Python can be done using various approaches. The most common method is the Transpose and Reverse technique, which converts rows to columns and then reverses each row to achieve a 90-degree clockwise rotation. Original Matrix Let's consider a 3×3 matrix that we want to rotate 90 degrees clockwise ? 1 5 7 9 6 3 2 1 3 Using Transpose and Reverse This method is efficient and involves two main steps ? Transpose the matrix ? Convert rows to columns and ...

Read More

Check if one list is subset of other in Python

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 25-Mar-2026 6K+ Views

Python provides various methods to check if one list is a subset of another. A subset means all elements of the smaller list exist in the larger list. We'll explore three effective approaches: all() function, issubset() method, and intersection() method. Using all() Function The all() function returns True if all elements in an iterable are true, otherwise False. We can combine it with a generator expression to check if every element of the sublist exists in the main list − # Define the main list and the sublist main_list = ['Mon', 'Tue', 5, 'Sat', 9] sub_list ...

Read More

Find Peak Element in Python

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 25-Mar-2026 5K+ Views

A peak element in an array is defined as an element that is greater than its neighbors. We can use some common approaches such as binary search to efficiently locate a peak element and linear search algorithm which involves iterating through an array. What is a Peak Element? A peak element is an element that is greater than or equal to its adjacent neighbors. For elements at the edges of the array, we only consider the existing neighbor ? # Example array with peak elements nums = [1, 3, 20, 4, 1, 0] # Here, 20 ...

Read More

Word Search in Python

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 25-Mar-2026 7K+ Views

In Python, word search refers to finding if a given word exists in a 2D grid. The word can be formed by sequentially connecting adjacent cells horizontally or vertically. This problem is commonly solved using backtracking and Depth-First Search (DFS) algorithms. Algorithm Overview The word search algorithm follows these key steps: Iterate through each cell in the 2D grid For each cell matching the first character, start a DFS search Use backtracking to explore all four directions (up, down, left, right) ...

Read More

File Upload Example in Python

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 25-Mar-2026 10K+ Views

File upload in Python can be implemented using the CGI (Common Gateway Interface) environment. This involves creating an HTML form for file selection and a Python script to handle the server−side file processing. The file upload process consists of two main components: an HTML form that allows users to select files, and a Python CGI script that processes and saves the uploaded files to the server. Creating HTML Form for File Upload The HTML form uses to create a file selection field and for the upload button. The form must include enctype="multipart/form-data" to handle file ...

Read More

Longest Substring Without Repeating Characters in Python

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 25-Mar-2026 8K+ Views

In Python, finding the longest substring without repeating characters is a classic string problem. We can solve this using different approaches: the Brute Force method which checks all possible substrings, and the more efficient Sliding Window technique using either a set or dictionary to track character positions. Common Methods The main approaches to find the longest substring without repeating characters are: Brute Force: Checks all possible substrings and verifies if they have unique characters. Sliding Window with Set: Uses a set to track characters in the current window and adjusts window boundaries dynamically. ...

Read More

Pass by reference vs value in Python

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 25-Mar-2026 12K+ Views

In Python Call by Value and Call by Reference are two types of generic methods to pass parameters to a function. In the Call-by-value method, the original value cannot be changed, whereas in Call-by-reference, the original value can be changed. Call by Value in Python When we pass an argument to a function, it is stored locally (in the stack memory), i.e the scope of these variables lies within the function and these will not affect the values of the global variables (variables outside function). In Python, "passing by value" is possible only with the immutable types ...

Read More
Showing 11–20 of 80 articles
« Prev 1 2 3 4 5 8 Next »
Advertisements