Programming Articles

Page 19 of 2547

Merging two strings with Suffix and Prefix using Python

Dr Ruqaiya Khanam
Dr Ruqaiya Khanam
Updated on 27-Mar-2026 730 Views

String manipulation often requires merging two strings based on shared suffix and prefix sequences. This article demonstrates how to merge two strings with overlapping parts using Python, avoiding redundant duplication while preserving all characters from both original strings. Understanding String Merging with Overlaps When merging strings, we need to identify if the suffix of the first string matches the prefix of the second string. For example, if we have "hello world" and "world peace", the word "world" appears at the end of the first string and the beginning of the second string. Smart merging would combine them as ...

Read More

Merging duplicates to list of lists

Dr Ruqaiya Khanam
Dr Ruqaiya Khanam
Updated on 27-Mar-2026 279 Views

When working with lists of lists in Python, you often encounter duplicate sublists that need to be removed. This article demonstrates two effective approaches to merge (remove) duplicate sublists while preserving unique entries. Using a For Loop The simplest approach uses a for loop to iterate through each sublist and check if it already exists in the result ? def merge_dups(input_list): output_list = [] for each_sublist in input_list: if each_sublist not in output_list: ...

Read More

Merging nested lists in Python

Dr Ruqaiya Khanam
Dr Ruqaiya Khanam
Updated on 27-Mar-2026 1K+ Views

Nested lists are lists that contain other lists as elements. Sometimes we need to flatten these nested structures into a single list containing all elements. Python provides several approaches to merge nested lists, each suited for different scenarios. Using Recursion for Deep Nesting The recursive approach handles lists with multiple levels of nesting by checking each element and recursively processing nested lists ? from collections.abc import Iterable def flatten(lst): for item in lst: if isinstance(item, Iterable) and not isinstance(item, (str, bytes)): ...

Read More

Minimum number of subsets with distinct elements using counter

Dr Ruqaiya Khanam
Dr Ruqaiya Khanam
Updated on 27-Mar-2026 369 Views

When working with collections of elements, we often need to find the minimum number of subsets where each subset contains only distinct (unique) elements. This problem is equivalent to counting the number of unique elements in the collection. Python provides two main approaches: manual counting with dictionaries and using the Counter class from the collections module. Understanding the Problem Given a list like [1, 2, 2, 3, 3, 3], the minimum number of subsets with distinct elements is 3, because we have 3 unique elements: {1}, {2}, and {3}. The frequency of each element determines how many times ...

Read More

Python program to generate a list of alphabets in lexical order

Dr Ruqaiya Khanam
Dr Ruqaiya Khanam
Updated on 27-Mar-2026 284 Views

Lexical order (also known as lexicographic or dictionary order) arranges words alphabetically by comparing characters from left to right. In this article, we will explore different methods to generate a list of alphabets in lexical order using Python. When placing words in lexical order, we compare character by character starting from the leftmost position. The first differing character determines the order. When characters are identical up to a point, the shorter word comes before the longer one. Understanding Lexical Order Consider this example of words in lexical order: apple baby banana boy car cat ...

Read More

Message Encode-Decode using Python Tkinter

Dr Ruqaiya Khanam
Dr Ruqaiya Khanam
Updated on 27-Mar-2026 549 Views

In this article, we'll learn how to create a message encoder-decoder application using Python Tkinter. Users can enter a message and select whether to encode or decode it. The encoded or decoded message will be displayed in the GUI window after clicking the respective button. What is Message Encoding? Message encoding transforms text into a different format. In our simple example, we'll use string reversal as our encoding method − reversing the character order makes text unreadable while keeping it easily decodable. Setting Up the GUI Application Let's create the Tkinter application step by step ? ...

Read More

Pattern Generation using Python time() module

Adeeba Khan
Adeeba Khan
Updated on 27-Mar-2026 398 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
Adeeba Khan
Updated on 27-Mar-2026 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
Adeeba Khan
Updated on 27-Mar-2026 362 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
Adeeba Khan
Updated on 27-Mar-2026 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
Showing 181–190 of 25,466 articles
« Prev 1 17 18 19 20 21 2547 Next »
Advertisements