Python Articles

Page 702 of 855

Python program to merge two Dictionaries

Hafeezul Kareem
Hafeezul Kareem
Updated on 25-Mar-2026 744 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 708 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 3K+ 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

10 Interesting Python Cool Tricks

Shriansh Kumar
Shriansh Kumar
Updated on 25-Mar-2026 6K+ Views

With the increase in popularity of the Python programming language, more and more features are becoming available for Python developers. Usage of these features helps us write efficient and cleaner code. In this article, we will explore 10 Python tricks that can make your code more concise and efficient. Reversing a List We can reverse a given list using the reverse() function. It modifies the original list in place and works with both numeric and string datatypes. Example Let's see how to use the reverse() function to reverse a list of strings ? ...

Read More

List comprehension and ord() in Python to remove all characters other than alphabets

Pavitra
Pavitra
Updated on 25-Mar-2026 275 Views

In this article, we will learn how to remove all non-alphabetic characters from a string using list comprehension and the ord() function in Python. This approach filters characters by checking their ASCII values. Algorithm The algorithm follows these steps: 1. Traverse the given string to check each character 2. Select characters that lie in the range [a-z] or [A-Z] using ord() 3. Use join() function to combine all valid characters into a string Understanding ord() Function The ord() function accepts a character as an argument and returns its corresponding ASCII value. This allows ...

Read More

Iterate over characters of a string in Python

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

In this article, we will learn about iterating over characters of a string in Python. A string is a collection of characters that can include spaces, alphabets, or integers, and we can access them using various iteration methods. Using Direct Iteration The simplest way to iterate over a string is to use a for loop directly ? text = "tutorialspoint" # Iterate over the string for char in text: print(char, end='') tutorialspoint Using Index-Based Access Access characters using their index positions with range() ? ...

Read More

isupper(), islower(), lower(), upper() in Python and their applications

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

In this article, we will learn about isupper(), islower(), upper(), and lower() functions in Python. These are built-in string methods that help determine and modify the case of alphabetic characters in strings. These functions are part of Python's Standard Library and work directly on string objects. The isupper() and islower() methods return boolean values, while upper() and lower() return new strings with modified case. Syntax All these methods are called on string objects and accept no arguments: string.isupper() # Returns True if all characters are uppercase string.islower() # Returns True if ...

Read More
Showing 7011–7020 of 8,549 articles
« Prev 1 700 701 702 703 704 855 Next »
Advertisements