Python | Remove all digits from a list of strings

Given a list of strings, write a Python program to remove all digits from the list of string.

Examples:

Input : ['alice1', 'bob2', 'cara3']
Output : ['alice', 'bob', 'cara']

Input : ['4geeks', '3for', '4geeks']
Output : ['geeks', 'for', 'geeks']

 

Method #1 : Python Regex

Python regex pattern can also be used to find if each string contains a digit or not and converting them to “”.

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program to Remove all 
# digits from a list of string
import re
  
def remove(list):
    pattern = '[0-9]'
    list = [re.sub(pattern, '', i) for i in list]
    return list
  
# Driver code 
  
list = ['4geeks', '3for', '4geeks']
print(remove(list))

chevron_right


Output:

['geeks', 'for', 'geeks']

 
Method #2 : Using str.maketrans() method
The maketrans() method returns a translation table that maps each character in the intabstring into the character at the same position in the outtab string. In this particular problem we translate each each digit to “” using for loop.

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program to Remove all 
# digits from a list of string
from string import digits
  
def remove(list):
    remove_digits = str.maketrans('', '', digits)
    list = [i.translate(remove_digits) for i in list]
    return list
  
# Driver code 
  
list = ['4geeks', '3for', '4geeks']
print(remove(list))

chevron_right


Output:

['geeks', 'for', 'geeks']

 
Method #3 : Using str.isalpha() method
In ,this approach we use two for loops and check if the character of string is an alphabet or not. If yes, join it within the list, otherwise leave it.

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program to Remove all 
# digits from a list of string
from string import digits
  
def remove(list):
    list = [''.join(x for x in i if x.isalpha()) for i in list]
              
    return list
  
# Driver code 
  
list = ['4geeks', '3for', '4geeks']
print(remove(list))

chevron_right


Output:

['geeks', 'for', 'geeks']


My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.