A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/python/python-remove-all-digits-from-a-list-of-strings/ below:

Python | Remove all digits from a list of strings

Python | Remove all digits from a list of strings

Last Updated : 11 Jul, 2025

The problem is about removing all numeric digits from each string in a given list of strings. We are provided with a list where each element is a string and the task is to remove any digits (0-9) from each string, leaving only the non-digit characters. In this article, we'll explore multiple methods to solve the problem.

Using Regular Expressions

Regular Expressions efficiently remove digits from strings by matching and replacing them. This uses the re.sub() function to substitute digits (\d) with an empty string. This method is very flexible for pattern matching and ideal for complex string manipulations.

Example:

Python
import re
s = ['Geeks123', 'for45', 'geeks678']

#Remove digit 
res= [re.sub(r'\d+', '', i) for i in s] 
print(res)

Output
['Geeks', 'for', 'geeks']

Explanation:

Let's discuss more method to remove all digits from a list of strings .

Using str.isdigit

str.isdigit checks if a character is a digit. This method iterates over each character in the string and checks if it's not a digit using char.isdigit(). Using list comprehension, this method removes all digits from each string while keeping the non-digit characters.

Example:

Python
s = ['Geeks123', 'for45', 'geeks678']

# Remove digit
res = [''.join([ch for ch in i if not ch.isdigit()]) for i in s]
print(res)

Output
['Geeks', 'for', 'geeks']

Explanation:

Using str.translate

It is a fast method to remove specific characters, like digits from strings. It directly replaces the specified characters with an empty string. str.translate() removes characters by using a translation table, created with str.maketrans(), which maps digits to None.

Example:

Python
s= ['Geeks123', 'for45', 'geeks678']
res= [i.translate(str.maketrans('', '', '0123456789')) for i in s] # Remove digit
print(res) 

Output
['Geeks', 'for', 'geeks']

Explanation:

Using filter

filter() removes digits from strings in list, keeping only non-digit characters. It simplifies string cleaning in a functional way. This method might be less efficient compared to translate() for removing large sets of characters.

Example:

Python
s= ['Geeks123', 'for45', 'geeks678']

# Remove digit
res= [''.join(filter(lambda ch: not ch.isdigit(), i)) for i in s] 
print(res)

Output
['Geeks', 'for', 'geeks']

Explanation:

Using str.replace

str.replace() in a loop remove digits from each string. It processes each digit (0-9) in every string, making it less efficient. This method is useful for small tasks or when working with small datasets where performance isn’t a concern.

Example:

Python
s = ['Geeks123', 'for45', 'geeks678']
for i in range(10):
    s = [string.replace(str(i), '') for string in s]  # Remove digit
print(s)

Output
['Geeks123', 'for45', 'geeks678']

Explanation:



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4