Articles on Trending Technologies

Technical articles with clear explanations and examples

What is the Python Global Interpreter Lock (GIL)

Pavitra
Pavitra
Updated on 25-Mar-2026 532 Views

The Python Global Interpreter Lock (GIL) is a mutex that protects access to Python objects, preventing multiple native threads from executing Python bytecodes at once. This lock is necessary mainly because CPython's memory management is not thread-safe. What is GIL? The GIL is a mechanism that ensures only one thread can execute Python code at a time. It acts as a bottleneck that prevents true parallelism in CPU-bound multithreaded Python programs, even on multi-core systems. Why was GIL introduced? Python uses automatic garbage collection based on reference counting. When an object's reference count drops to zero, ...

Read More

Vectorization in Python

Pavitra
Pavitra
Updated on 25-Mar-2026 1K+ Views

Vectorization is a technique that replaces explicit loops with array operations, significantly improving performance in numerical computations. Instead of iterating through elements one by one, vectorized operations work on entire arrays at once using optimized C libraries. What is Vectorization? Vectorization implements array operations without explicit loops, using functions that operate on entire arrays simultaneously. This approach minimizes running time by leveraging optimized libraries like NumPy, which use efficient C implementations under the hood. Common vectorized operations include: Dot product − Produces a single scalar value from two vectors Outer product − Creates a matrix ...

Read More

Program to reverse an array up to a given position in Python

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

In this tutorial, we will learn how to reverse an array up to a given position. This means reversing elements from index 0 to index (n-1), while keeping the remaining elements in their original positions. Problem Statement Given an array of integers and a number n, reverse the elements from the 0th index to (n-1)th index ? Input: array = [1, 2, 3, 4, 5, 6, 7, 8, 9], n = 5 Output: [5, 4, 3, 2, 1, 6, 7, 8, 9] Method 1: Using Swapping This approach swaps elements from both ...

Read More

Python program to remove leading zeros from an IP address

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

In this tutorial, we will write a Python program to remove leading zeros from an IP address. For example, if we have an IP address 255.001.040.001, we need to convert it to 255.1.40.1. Approach The solution involves these steps − Split the IP address by dots using split() Convert each part to integer (automatically removes leading zeros) Convert back to strings and join with dots Example Here's how to remove leading zeros from an IP address − # Initialize IP address with leading zeros ip_address = "255.001.040.001" # Split using ...

Read More

Python program to merge two Dictionaries

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

In this tutorial, we are going to learn how to combine two dictionaries in Python. Let's see different ways to merge two dictionaries. Using update() Method The update() method is an inbuilt dictionary method that merges one dictionary into another. It returns None and modifies the original dictionary in place ? # initializing the dictionaries fruits = {"apple": 2, "orange": 3, "tangerine": 5} dry_fruits = {"cashew": 3, "almond": 4, "pistachio": 6} # updating the fruits dictionary fruits.update(dry_fruits) # printing the fruits dictionary # it contains both the key: value pairs print(fruits) ...

Read More

Python program to find all duplicate characters in a string

Sarika Singh
Sarika Singh
Updated on 25-Mar-2026 41K+ Views

This article teaches you how to write a Python program to find all duplicate characters in a string using different approaches. Characters that repeat themselves within a string are referred to as duplicate characters. When we refer to finding duplicate characters in a string, we mean identifying every character that appears more than once in the string. Input-Output Scenario Following is the input-output scenario to find all the duplicate characters in a string ? Input: TutorialsPoint Output: t, o, i As we can see, the duplicate characters in the given string "TutorialsPoint" are ...

Read More

Python program to find all close matches of input string from a list

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

In this tutorial, we will find all strings from a list that closely match a given input string. A close match means either the string starts with the input element or the input element starts with the string. Problem Statement Given a list of strings and an input element, find all strings that have a close match with the element ? Input: strings = ["Lion", "Li", "Tiger", "Tig"] element = "Lion" Output: Lion Li Algorithm We can solve this using the startswith() method with the following steps ? Initialize ...

Read More

Program to check if all the values in a list that are greater than a given value in Python

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

In this tutorial, we will check whether all the elements in a list are greater than a given number or not. For example, we have a list [1, 2, 3, 4, 5] and a number 0. If every value in the list is greater than the given value, we return True, otherwise False. Python provides multiple approaches to solve this problem efficiently. Let's explore different methods to implement this logic. Method 1: Using a Loop The basic approach involves iterating through each element and checking if any value is less than or equal to the given number ...

Read More

Permutation of a given string using the inbuilt function in Python

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

In this tutorial, we will find the permutation of a string using Python's built-in permutations() function from the itertools module. A permutation is a rearrangement of all characters in a string where each character appears exactly once. How It Works The itertools.permutations() method generates all possible arrangements of the input string's characters and returns them as tuples in an iterator object. Step-by-Step Process Import the itertools module Initialize the string Use itertools.permutations() to generate all permutations Convert the iterator to a list of tuples Join each tuple to form readable strings Example ...

Read More

Binary Search (bisect) in Python

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

The bisect module in Python provides functions for binary search operations on sorted lists. Binary search is an efficient algorithm that finds elements in O(log n) time complexity, making it much faster than linear search for large datasets. We will explore three common binary search operations using the bisect module ? Finding First Occurrence of an Element The bisect_left() function returns the leftmost insertion point for a value in a sorted list. This helps us find the first occurrence of an element ? Syntax bisect.bisect_left(a, x, lo=0, hi=len(a)) Parameters: a - ...

Read More
Showing 7051–7060 of 61,298 articles
« Prev 1 704 705 706 707 708 6130 Next »
Advertisements