Yaswanth Varma

Yaswanth Varma

307 Articles Published

Articles by Yaswanth Varma

Page 28 of 31

How to convert a string to a list of words in python?

Yaswanth Varma
Yaswanth Varma
Updated on 20-May-2025 10K+ Views

Strings are one of the most commonly used data types. In this article, we are going to find out how to convert a string to a list of words in Python. Converting the string into a list is helpful when dealing with user inputs or when we want to manipulate individual words in a string. Python provides several ways to achieve this. Let's explore them one by one. Using Python str.split() Method Python str.split() method accepts a separator as a parameter, splits the string at the specified separator, and returns the result as a list. If we use the split() ...

Read More

How to sort the letters in a string alphabetically in Python?

Yaswanth Varma
Yaswanth Varma
Updated on 20-May-2025 7K+ Views

In Python, Sorting the string alphabetically is a common task helps for string manipulation or text analysis. It is used in creating the anagrams, checking for permutations, or standardizing the input for consistent processing, for example, turning 'banana' into 'aaabnn'. In this article, we will explore how to sort the letters in a string alphabetically, this can be done by using the Python built-in function. Using Python sorted() Function The Python sorted() function is used to return a new sorted list from the items in the iterable object. The order of sorting can be set to either ascending ...

Read More

How to find the longest common substring from more than two strings in Python?

Yaswanth Varma
Yaswanth Varma
Updated on 08-May-2025 2K+ Views

The substrings are the sequence of characters that appear within the string. While working with multiple strings, it is useful to find the longest common substring. There are various ways to find the longest common substring from more than two strings. one of the most common approach is using the dynamic programming. Let's dive into the article to learn more about this task. Using Dynamic Programming In this approach, we are going to use the dynamic programming (DP), Here we compare the strings pairwise (starting with first two strings), we find their longest common substring using a DP ...

Read More

How to do string concatenation without \'+\' operator in Python?

Yaswanth Varma
Yaswanth Varma
Updated on 07-May-2025 3K+ Views

In this article, we are going to find out how to do string concatenation without the plus operator in Python. Generally, String concatenation is the process of joining two or more strings into one, and the common way to do this is by using the '+' operator. For example, writing "Welcome" + " " + "TP" results in the string "Welcome TP". But here we need to perform the concatenation without the '+' operator. For achieving this, Python provides alternative methods, which we will explore one by one. Using Python join() Method The first approach is ...

Read More

How to remove all special characters, punctuation and spaces from a string in Python?

Yaswanth Varma
Yaswanth Varma
Updated on 02-May-2025 7K+ Views

It is necessary to clean up the strings by removing the unwanted elements such as special characters, punctuation, and spaces. These unwanted characters can be involved in the tasks and cause unexpected results. In this article, we are going to learn more about removing all special characters, punctuation and spaces from a string. Using Python re Module Through the re module, Python provides support for regular expressions. This module contains methods and classes that we can search, match, and modify a string (text content) using regular expressions.ThePython re.sub() method accepts a pattern, a replacement string, and a string as ...

Read More

How to check if multiple strings exist in another string in Python?

Yaswanth Varma
Yaswanth Varma
Updated on 21-Apr-2025 11K+ Views

While working with the strings, Checking if the string exists inside another string is a common task and can be achieved by using the in keyword. But, In this article we are going to see how to check if multiple strings exist in another string in Python. For example, checking the multiple strings: "TP", "WELCOME", exists in the string "WELCOME to TP". For achieving this, Python provides different methods including loops, any() and all(). Using Python any() Function The Python any() function returns true if any of the element of the given iterable (such as list, ...

Read More

What is the most elegant way to check if the string is empty in Python?

Yaswanth Varma
Yaswanth Varma
Updated on 21-Apr-2025 4K+ Views

The strings are the fundamental data types that are used to store text. When working with the string, Checking if the string is empty or not is a common task. An empty string is nothing but the string with zero characters. There are various to check if a sting is empty, But choosing the elegant ways helps to improve the code readability. Let's dive into the article to learn more about it. Using if not my_string In Python, empty strings are considered as falsy, Which evaluates to false in a boolean content. So using not my_string returns true ...

Read More

How to remove empty strings from a list of strings in Python?

Yaswanth Varma
Yaswanth Varma
Updated on 21-Apr-2025 9K+ Views

The Lists in Python are used to store collections of items such as numbers, strings. While working with the list of strings, it is common to find a empty strings in the list. An empty string is nothing but a string value with zero length. Officially they are present as elements in the list, but does not hold any data and interfere in the operations like sorting, filtering. So, removing the empty strings is essential to ensure the list contains only valid values. For achieving this, Python provides the several ways. Let's dive into the article to learn ...

Read More

How to process escape sequences in a string in Python?

Yaswanth Varma
Yaswanth Varma
Updated on 21-Apr-2025 3K+ Views

The escape sequences are the special characters that are used to represent the whitespace characters, quotes, backslashes or non-printable characters within the string. These sequences start with the backslash followed by the character, For example result in newline. However, in some cases we will come across the situations to process or even to ignore these situations. In this article we will learn how to process the escape sequences. Example Let's look at the following example, where we are going to consider the basic approach to process the escape sequences. str1 = "Hello\tEveryoneWelcome to TutorialsPoint" print(str1) ...

Read More

How to convert hex string into int in Python?

Yaswanth Varma
Yaswanth Varma
Updated on 16-Apr-2025 48K+ Views

A Hexadecimal is the base-16 number system that uses the digits from the '0 to 9' and letters from 'A to F'. It is commonly used in the computers to represent the binary data in the readable format. In this article we are going to learn about converting hex string into int. For example, if we receive the input as a hex string("12xf2") and need to convert it into a integer. For achieving this, Python provides the multiple methods let's explore them one by one. Using Python int() Function The Python int() function is used to convert ...

Read More
Showing 271–280 of 307 articles
Advertisements