Dr Ruqaiya Khanam

Dr Ruqaiya Khanam

13 Articles Published

Articles by Dr Ruqaiya Khanam

13 articles

Merging two list of dictionaries in Python

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

When working with Python data structures, you may need to combine multiple lists of dictionaries into a single list. This operation preserves all dictionaries from both lists while maintaining their original order and structure. In this article, we'll explore two effective methods for merging lists of dictionaries: the + operator and the extend() method. Both approaches create a unified list containing all dictionaries from the input lists. Using the '+' Operator The + operator creates a new list by concatenating two existing lists without modifying the original lists ? # Define two lists of dictionaries ...

Read More

Merging two strings with Suffix and Prefix using Python

Dr Ruqaiya Khanam
Dr Ruqaiya Khanam
Updated on 27-Mar-2026 725 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 269 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 359 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 280 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 540 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

Finding the Maximum and Minimum in a Python set

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

Python sets store unique elements in an unordered collection. To find the maximum and minimum values in a set, Python provides several approaches using built-in functions like max(), min(), and sorted(). Using Built-in max() and min() Functions The most direct approach is to apply max() and min() functions directly to the set ? # Define a set with integer values numbers = {5, 2, 8, 1, 9, 18} # Find maximum and minimum values directly maximum = max(numbers) minimum = min(numbers) print("Maximum:", maximum) print("Minimum:", minimum) Maximum: 18 Minimum: 1 ...

Read More

Python program to find volume, surface area and space diagonal of a cuboid

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

In this article, we will discuss how to compute the volume, surface area, and space diagonal of a cuboid. A cuboid is a 3D geometric shape that resembles a rectangular box, also called a rectangular prism. It has six rectangular faces with twelve edges, where length, breadth, and height are different (unlike a cube where all sides are equal). Understanding Cuboid Formulas Before implementing the code, let's understand the key formulas ? Volume: length × breadth × height Surface Area: 2 × (l×b + b×h + h×l) Space Diagonal: √(l² + b² + h²) ...

Read More

Python Program to get all Possible Slices of a String for K Number of Slices

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

Getting all possible slices of a string for K number of slices means dividing a string into exactly K parts in all possible ways. Python provides multiple approaches to solve this problem: iteration and using itertools.combinations. Method 1: Using Iterative Approach This method builds slices iteratively by extending existing slices from previous iterations ? def get_all_slices_iteration(string, k): slices = [[]] for i in range(k): new_slices = [] ...

Read More
Showing 1–10 of 13 articles
« Prev 1 2 Next »
Advertisements