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

Pavitra
Updated on 25-Mar-2026 06:08:44

294 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
Updated on 25-Mar-2026 06:08:24

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
Updated on 25-Mar-2026 06:08:08

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

Intersection() function Python

Pavitra
Updated on 25-Mar-2026 06:07:46

333 Views

In this article, we will learn about the intersection() function that can be performed on any given set. According to mathematics, intersection means finding common elements from two or more sets. Set A {1, 2, 3, 4} Set B {3, 4, 5, 6} 3, 4 Intersection Set Intersection Syntax .intersection(, , ...) ... Read More

The intersection of two arrays in Python (Lambda expression and filter function )

Pavitra
Updated on 25-Mar-2026 06:07:26

798 Views

In this article, we will learn about finding the intersection of two arrays in Python using lambda expressions and the filter function. The intersection contains elements that are common to both arrays. The problem is that we are given two arrays and we need to find the common elements between them using functional programming concepts. Algorithm Here's the step-by-step approach ? Declare an intersection function with two array parameters Use a lambda expression with the filter function to select elements from the second array that exist in the first array Convert the filtered result to ... Read More

Inplace Operators in Python - ixor(), iand(), ipow()

Pavitra
Updated on 25-Mar-2026 06:07:09

363 Views

In this article, we will learn about some of the inplace operators available in Python's operator module. Python provides methods to perform inplace operations, combining assignment and computation simultaneously using a single statement. Here we will discuss three important inplace operators: ixor(), iand(), and ipow() functions. ixor() - Inplace XOR Operation This function performs an inplace XOR (exclusive or) operation. It behaves like the a ^= b operation, computing the bitwise XOR of two values ? import operator as op # using ixor() to perform XOR operation result = op.ixor(786, 12) # displaying ... Read More

Initialize Matrix in Python

Pavitra
Updated on 25-Mar-2026 06:06:45

4K+ Views

In this article, we will learn how to initialize a matrix using two dimensional lists in Python. A matrix is a rectangular array of numbers arranged in rows and columns, which can be represented as a list of lists in Python. Let's explore different methods to initialize matrices, taking advantage of Python's list comprehension feature for clean and efficient code. Method 1: Using List Comprehension List comprehension provides an intuitive way to initialize matrices. We create the inner lists first and then extend to multiple rows ? # Define matrix dimensions rows = 3 cols ... Read More

__name__ (A Special variable) in Python

Sarika Singh
Updated on 25-Mar-2026 06:06:05

3K+ Views

Python does not require a main function to start execution like many other programming languages. Instead, it uses a special built-in variable called __name__ to determine how a Python script is being executed (directly or imported as a module into another script). In this article, we will learn about the __name__ variable in Python and how to use it effectively. Understanding the __name__ Variable The __name__ variable is a built-in variable that holds the name of the current module. When you run a script directly, Python sets __name__ to __main__. If the same script is ... Read More

Using Iterations in Python Effectively

karthikeya Boyini
Updated on 25-Mar-2026 06:05:44

308 Views

In this article, we will learn about different iteration methods in Python and their effective implementation. Python provides several approaches to iterate through data structures, each with its own advantages and use cases. Using While Loop with Index This method uses a while loop with manual index management ? languages = ("Python", "C", "C++", "Java") print("The topics available on TutorialsPoint are:") i = 0 while (i < len(languages)): print(languages[i]) i += 1 The topics available on TutorialsPoint are: Python C C++ Java This ... Read More

Using List as Stack and Queues in Python

karthikeya Boyini
Updated on 25-Mar-2026 06:05:23

7K+ Views

In this article, we will learn how to implement Stack and Queue data structures using Python lists. Both are fundamental data structures with different ordering principles: stacks follow LIFO (Last In First Out) while queues follow FIFO (First In First Out). We'll cover the core operations for both structures − Insertion operation (Push for stacks, Enqueue for queues) Deletion operation (Pop for stacks, Dequeue for queues) Display / Traversing operation ... Read More

Advertisements