Programming Articles

Page 41 of 2547

Finding the Cartesian product of strings using Python

Pranavnath
Pranavnath
Updated on 27-Mar-2026 509 Views

The Cartesian product of strings creates all possible combinations between elements from different sets. Python provides several approaches to find the Cartesian product of strings using itertools.product(), nested loops, and lambda functions. Using itertools.product() The itertools.product() function provides the most straightforward way to generate Cartesian products ? import itertools # Define two sets of strings set1 = ["welcome", "all", "here"] set2 = ["see", "you", "soon"] # Generate Cartesian product using itertools.product() cart_product = list(itertools.product(set1, set2)) # Concatenate strings from each tuple result = [a + b for a, b in cart_product] print(result) ...

Read More

Python3 Program for Longest subsequence of a number having same left and right rotation

Shubham Vora
Shubham Vora
Updated on 27-Mar-2026 197 Views

In this problem, we will find the length of the longest subsequence of a given numeric string such that it has the same left and right rotation. A string has the same left and right rotation when rotating left by one position produces the same result as rotating right by one position. We can solve this problem using two approaches: generating all subsequences and checking rotations, or using an optimized observation-based method that recognizes patterns in valid subsequences. Problem Statement Given a numeric string, find the size of the longest subsequence that has the same left and ...

Read More

Python3 Program to Find Maximum number of 0s placed consecutively at the start and end in any rotation of a Binary String

Shubham Vora
Shubham Vora
Updated on 27-Mar-2026 244 Views

In this problem, we need to find the maximum sum of consecutive zeros at the start and end of any rotation of a binary string. We can solve this using two approaches: generating all rotations or using an optimized observation-based method. Problem Statement − Find the total number of maximum consecutive zeros at the start and end of any rotation of the given binary string. Examples Example 1 binary_str = "00100100" print(f"Input: {binary_str}") Input: 00100100 Output: 4 Explanation − Let's examine all rotations: 00100100 − Starting zeros: 2, ...

Read More

Python3 Program for Queries for Rotation and Kth Character of the given String in Constant Time

Shubham Vora
Shubham Vora
Updated on 27-Mar-2026 177 Views

In this problem, we need to perform queries on a string efficiently. We'll handle two types of queries: left rotation and character access. We'll explore two approaches - a straightforward string manipulation method and an optimized pointer-based solution. Problem Statement Given a string and an array of queries, perform operations based on query types ? (1, l) − Perform left rotation of the string l times (2, l) − Access and print the character at position l (1-indexed) Example Let's see how the queries work with a sample input ? # ...

Read More

Dumping queue into list or array in Python

Prabhdeep Singh
Prabhdeep Singh
Updated on 27-Mar-2026 607 Views

A queue is a linear data structure that follows the FIFO (First In, First Out) principle. While queues only allow access to the front element, sometimes we need to convert the entire queue into a list for easier manipulation. Python provides multiple approaches to dump queue contents into a list. Creating a Queue in Python Python offers two main queue implementations: collections.deque and queue.Queue. Let's first see how a basic queue works ? from collections import deque # Create and populate a queue queue = deque() queue.append(1) queue.append(2) queue.append(3) queue.append(4) print("Queue contents:", queue) ...

Read More

Handling Missing Data in Python Causes and Solutions

Satish Kumar
Satish Kumar
Updated on 27-Mar-2026 604 Views

Missing data is a common challenge in data analysis that can significantly impact results. In Python, missing values are typically represented as NaN (Not a Number) or None. Understanding the causes and applying appropriate solutions is crucial for accurate analysis. Common Causes of Missing Data Data Entry Errors Human errors during manual data entry are frequent causes of missing values. These can include skipped fields, typos, or accidental deletions during data input processes. Incomplete Data Collection Survey non-responses, equipment failures, or incomplete forms can result in gaps in datasets. Time constraints and budget limitations may ...

Read More

Allowing resizing window in PyGame

Priya Mishra
Priya Mishra
Updated on 27-Mar-2026 2K+ Views

Pygame is a Python module for game development that provides graphics and sound libraries. By default, Pygame windows are not resizable, but you can make them resizable by adding the pygame.RESIZABLE flag. Installation of PyGame Install Pygame using pip in your terminal or command prompt ? pip install pygame Creating a Normal (Non-Resizable) Window Here's how to create a basic Pygame window that cannot be resized ? import pygame # Initialize pygame pygame.init() # Create a non-resizable window screen = pygame.display.set_mode((400, 300)) pygame.display.set_caption('Non-Resizable Window') # Main game loop ...

Read More

Animate image using OpenCV in Python

Priya Mishra
Priya Mishra
Updated on 27-Mar-2026 2K+ Views

Animated images are sequences of static images played continuously to create dynamic visual content. They're smaller than videos and widely supported across web and mobile platforms. OpenCV provides powerful tools to create animated effects by manipulating image sequences in Python. What is OpenCV? OpenCV (Open Source Computer Vision Library) is a comprehensive library for computer vision, machine learning, and image processing. Originally developed by Gary Bradsky at Intel in 1999, it now supports multiple programming languages including Python, C++, and Java across various platforms. OpenCV provides extensive functionality for image manipulation, video processing, and real-time computer vision ...

Read More

Fromisoformat() Function of Datetime.date Class in Python

Jaisshree
Jaisshree
Updated on 27-Mar-2026 2K+ Views

The datetime.date class in Python provides a convenient way to represent and manipulate dates. The fromisoformat() method allows you to create a date object from a string in ISO 8601 format ("YYYY-MM-DD"). This method is particularly useful when parsing dates from log files, APIs, or any data source that provides dates in the standard ISO format. Syntax datetime.date.fromisoformat(date_string) Parameters: date_string − A string representing a date in ISO format "YYYY-MM-DD" Return Value: Returns a datetime.date object representing the parsed date. Example 1: Creating a Date Object from ISO String ...

Read More

Finding the Number of Weekdays of a Given Month in NumPy

Jaisshree
Jaisshree
Updated on 27-Mar-2026 423 Views

NumPy is a powerful Python library for numerical computing and data analysis. When working with date calculations, you often need to count weekdays (business days) within a specific month, excluding weekends and holidays. You can install NumPy using pip ? pip install numpy NumPy's busday_count() function calculates the number of business days (Monday to Friday) between two specific dates. Syntax numpy.busday_count(startdate, enddate, weekmask='1111100', holidays=None) Parameters startdate − Start date (inclusive) in "YYYY-MM-DD" format enddate − End date (exclusive) in "YYYY-MM-DD" format weekmask − Optional string defining valid weekdays ...

Read More
Showing 401–410 of 25,469 articles
« Prev 1 39 40 41 42 43 2547 Next »
Advertisements