Pattern Generation using Python time() module

Adeeba Khan
Updated on 27-Mar-2026 15:38:05

394 Views

Pattern generation is a fundamental programming concept that involves creating ordered sequences or structures. Python's time module provides tools for working with time-related operations and can be creatively used to generate dynamic patterns that change over time. This article explores two approaches for creating patterns using Python's time() function: using time as a random seed for pattern generation and creating patterns directly based on current time components. Method 1: Using Time as Random Seed This approach uses the current time as a seed for the random number generator to ensure unique patterns are generated each time. Random ... Read More

Python - Number Theoretic Transformation

Adeeba Khan
Updated on 27-Mar-2026 15:37:40

1K+ Views

The Number Theoretic Transformation (NTT) is a mathematical technique used for efficient polynomial multiplication and convolution operations. It's closely related to the Fast Fourier Transform (FFT) but operates in finite fields, making it particularly useful in cryptography, error-correcting codes, and number theory applications. In this article, we'll explore two implementations of NTT using the Cooley-Tukey algorithm: one using complex numbers (traditional FFT) and another using modular arithmetic with integers. Method 1: Using Complex Numbers (Traditional FFT) The Cooley-Tukey FFT algorithm can be adapted for NTT by working with complex exponentials. This approach uses the divide-and-conquer strategy to ... Read More

Python- Percentage occurrence at index

Adeeba Khan
Updated on 27-Mar-2026 15:37:16

358 Views

In this article, we will learn how to calculate the percentage occurrence of a value at a specific index in a list. This computation helps analyze data distribution and patterns by determining how frequently the value at a given index appears throughout the entire list. For Example: data = [4, 2, 3, 1, 5, 6, 7] print(f"List: {data}") print(f"Value at index 2: {data[2]}") List: [4, 2, 3, 1, 5, 6, 7] Value at index 2: 3 The value 3 occurs at index 2 and appears only once in the entire list. The ... Read More

Finding the Peak Signal-to-Noise Ratio (PSNR) using Python

Adeeba Khan
Updated on 27-Mar-2026 15:36:54

4K+ Views

Peak Signal-to-Noise Ratio (PSNR) is a widely used metric to measure the quality of digital signals, particularly for images and video. It quantifies the difference between original and distorted versions of a signal, measuring the amount of noise added through compression, transmission, or processing. PSNR is utilized in multimedia applications, video compression, and image processing. In this article, we'll explore two methods for calculating PSNR in Python. Understanding Peak Signal-to-Noise Ratio PSNR is a standard metric for evaluating image or video quality. It's frequently used in compression algorithms to compare the quality of compressed output against the original ... Read More

Python - Percentage similarity of lists

Adeeba Khan
Updated on 27-Mar-2026 15:36:29

1K+ Views

Measuring the similarity between two lists is a common task in Python applications like data analysis, text processing, and recommendation systems. This article explores two methods to calculate percentage similarity between lists based on shared elements. List similarity is determined by analyzing overlap or shared elements between lists. This provides a numerical assessment of how much two lists have in common, expressed as a percentage. The choice of method depends on whether you need to handle duplicates and how you want to calculate the similarity ratio. Method 1: Using Set Intersection This approach uses Python's set data ... Read More

Python - Number of positions where Substrings Match of Length K

Nikitasha Shrivastava
Updated on 27-Mar-2026 15:36:03

278 Views

In string processing, we often need to find how many times a substring of specific length appears at different positions in a string. This tutorial demonstrates how to count the number of positions where substrings of length K match a given pattern using Python. Understanding the Problem Given an input string, we need to find how many positions contain a specific substring of length K. For example, if we search for "aaab" (K=4) in the string "aaabddhaaabnsnsaaabkskd", we need to count all occurrences at different positions. Input String: aaabddhaaabnsnsaaabkskd Pattern: aaab (K=4) ... Read More

Python - Nth smallest Greater than K

Nikitasha Shrivastava
Updated on 27-Mar-2026 15:35:36

237 Views

The task of finding the Nth smallest element greater than K is a common problem in data analysis. Python provides several efficient approaches using filtering and sorting techniques to solve this challenge. Understanding the Problem We need to find the Nth smallest number that is greater than a given value K from a list. For example, if we have numbers [2, 6, 4, 7, 8, 10, 15, 9], K=5, and N=3, we first filter numbers greater than 5: [6, 7, 8, 10, 15, 9], then sort them: [6, 7, 8, 9, 10, 15], and return the 3rd element: ... Read More

Python - Non-overlapping Random Ranges

Nikitasha Shrivastava
Updated on 27-Mar-2026 15:35:08

253 Views

Generating non-overlapping random ranges is useful in data analysis, sampling, and testing scenarios. Python's random module provides tools to create ranges that don't intersect with each other. Understanding the Problem Given a start value, end value, and number of ranges needed, we generate random ranges that don't overlap. For example, with start=1, end=50, and 3 ranges, we might get [(5, 8), (15, 22), (35, 40)]. Method 1: Simple Range Generation This approach generates random ranges but doesn't guarantee they won't overlap ? import random def simple_ranges(start, end, num_ranges): ranges ... Read More

Python - Non-Overlapping occurrences of N Repeated K character

Nikitasha Shrivastava
Updated on 27-Mar-2026 15:34:46

196 Views

In this article, we'll find the non-overlapping occurrences of N repeated K characters using Python. This is a common string processing problem where we need to count how many times a specific character appears consecutively a given number of times. Understanding the Problem Given a string, we need to find non-overlapping occurrences where character K appears exactly N consecutive times. For example, in string "AABBCCAAA", if K="A" and N=2, we look for "AA" patterns that don't overlap. String: AABBCCAAA Looking for K='A' repeated N=2 times AA ... Read More

Python - Non-None elements indices

Nikitasha Shrivastava
Updated on 27-Mar-2026 15:34:18

215 Views

The problem at hand is to get the indices of non-None elements in a given input list. This is useful when working with datasets containing missing or empty values represented as None. Understanding the Problem Given a list containing some None values, we need to find the indices of all non-None elements. For example, given the list [1, None, 5, None, 8, 9], we should return [0, 2, 4, 5] as these are the positions of non-None values. Method 1: Using a For Loop The basic approach iterates through the list and checks each element ? ... Read More

Advertisements