How to remove all digits from a list of strings in Python

2 Answers

0 votes
import re 

def remove_digits(lst): 
    pattern = '[0-9]'
    lst = [re.sub(pattern, '', c) for c in lst] 
    return lst
  
lst = ['12python', 'java76script', 'node.js56', '2c++2'] 

lst = remove_digits(lst)
 
print(lst)
 
      
     
'''
run:

['python', 'javascript', 'node.js', 'c++']
     
'''

 



answered Mar 27, 2020 by avibootz
0 votes
def remove_digits(lst): 
    lst = [''.join(c for c in i if c.isalpha()) for i in lst] 
    return lst
  
lst = ['12python', 'java76script', 'node.js56', '2c++2'] 

lst = remove_digits(lst)
 
print(lst)
 
      
     
'''
run:

['python', 'javascript', 'nodejs', 'c']
     
'''

 



answered Mar 27, 2020 by avibootz
...