Server Side Programming Articles

Page 550 of 2109

String Transforms Into Another String in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 1K+ Views

Sometimes we need to check if we can transform one string into another by converting all occurrences of specific characters. This problem involves character mapping and transformation rules to determine if str1 can be converted to str2. In one conversion, we can convert all occurrences of one character in str1 to any other lowercase English character. The key constraint is that we need at least one "free" character (not used in str2) to perform intermediate conversions. Problem Example Given str1 = "aabcc" and str2 = "ccdee", we can transform str1 to str2 ? Convert 'c' ...

Read More

Parallel Courses in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 293 Views

The parallel courses problem involves finding the minimum number of semesters needed to complete N courses with prerequisite dependencies. This is essentially a topological sorting problem that can be solved using BFS (Breadth-First Search). Problem Understanding Given N courses labeled 1 to N and a relations array where relations[i] = [X, Y] means course X must be completed before course Y. We need to find the minimum semesters required to complete all courses, or return -1 if impossible due to circular dependencies. Algorithm Approach We use topological sorting with BFS to process courses level by level ...

Read More

Divide Array Into Increasing Sequences in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 302 Views

Suppose we have a non-decreasing array of positive integers called nums and an integer K. We need to determine if this array can be divided into one or more disjoint increasing subsequences, each of length at least K. For example, if the input is nums = [1, 2, 2, 3, 3, 4, 4] and K = 3, the output will be True because this array can be divided into two subsequences: [1, 2, 3, 4] and [2, 3, 4], both with lengths at least 3. Algorithm Approach The key insight is that we need to find the ...

Read More

time.process_time() function in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 25-Mar-2026 2K+ Views

The time.process_time() function in Python returns the sum of system and user CPU time consumed by the current process. Unlike time.time(), it excludes time spent sleeping and focuses only on actual processing time. Syntax time.process_time() This function returns a float value representing the CPU time in seconds. Basic Example Here's how to get the current process time ? import time # Get current process time current_time = time.process_time() print(f"Current process time: {current_time} seconds") Current process time: 0.015625 seconds Measuring Execution Time The most common ...

Read More

time.perf_counter() function in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 25-Mar-2026 4K+ Views

In this tutorial, we are going to learn about the time.perf_counter() method in Python. This function is part of the time module and provides the highest available resolution to measure a short duration. The method time.perf_counter() returns a float value representing time in seconds. It includes time elapsed during sleep and is system-wide, making it ideal for measuring elapsed time in code execution. Basic Usage Let's start with a simple example to see how perf_counter() works ? import time # Get current performance counter value print("Current time:", time.perf_counter()) Current time: 263.3530349 ...

Read More

The most occurring number in a string using Regex in python

Hafeezul Kareem
Hafeezul Kareem
Updated on 25-Mar-2026 289 Views

In this tutorial, we will write a regex that finds the most occurring number in a string using Python. We'll use the re module for pattern matching and collections.Counter for frequency counting. Steps to Find the Most Occurring Number Import the re and collections modules Initialize the string containing numbers Find all numbers using regex and store them in a list Find the most occurring number using Counter from collections module Example Here's how to implement this solution ? # importing the modules import re import collections # initializing the string ...

Read More

Taking multiple inputs from user in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 25-Mar-2026 1K+ Views

In this tutorial, we are going to learn how to take multiple inputs from the user in Python. The data entered by the user will be in the string format. So, we can use the split() method to divide the user entered data. Taking Multiple String Inputs Let's take multiple strings from the user using split() ? # taking the input from the user strings = input("Enter multiple names space-separated:- ") # splitting the data strings = strings.split() # printing the data print(strings) The output of the above code is ? ...

Read More

Take Matrix input from user in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 25-Mar-2026 9K+ Views

In this tutorial, we will learn how to take matrix input from the user in Python. There are two common approaches: taking individual elements one by one, or taking entire rows with space-separated values. Method 1: Taking Individual Elements This method asks the user to input each matrix element individually ? Example # initializing an empty matrix matrix = [] # taking 2x2 matrix from the user for i in range(2): # empty row row = [] for j in range(2): ...

Read More

Sum of list (with string types) in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 25-Mar-2026 3K+ Views

In this tutorial, we'll write a program that adds all numbers from a list containing mixed data types. The list may contain numbers in string or integer format, along with non-numeric strings. Problem Statement Given a list with mixed data types, we need to sum only the numeric values (both integers and numeric strings) while ignoring non-numeric strings ? Input random_list = [1, '10', 'tutorialspoint', '2020', 'tutorialspoint@2020', 2020] Expected Output 4051 Solution Approach Follow these steps to solve the problem: Initialize the list with mixed data ...

Read More

Structuring Python Programs

Hafeezul Kareem
Hafeezul Kareem
Updated on 25-Mar-2026 534 Views

In this tutorial, we are going to see some best practices for structuring Python programs. Following these conventions makes your code more readable and maintainable. Use Consistent Indentation Python uses indentation to define code blocks. Use 4 spaces per indentation level as recommended by PEP 8. Avoid mixing tabs and spaces ? def calculate_area(length, width): # 4 spaces for indentation if length > 0 and width > 0: area = length * width ...

Read More
Showing 5491–5500 of 21,090 articles
« Prev 1 548 549 550 551 552 2109 Next »
Advertisements