How to remove a given character from a list of strings in Python

2 Answers

0 votes
lst = ["python", "java", "PHP", "c#", "pascal"] 

ch = 'p'
for i, ele in enumerate(lst): 
        lst[i] = ele.replace(ch, '') 

print(lst) 



'''
run:

['ython', 'java', 'PHP', 'c#', 'ascal']

'''

 



answered Jan 13, 2020 by avibootz
0 votes
lst = ["python", "java", "PHP", "c#", "pascal"] 

ch = 'p'

lst = [ele.replace(ch, '') for ele in lst] 

print(lst) 



'''
run:

['ython', 'java', 'PHP', 'c#', 'ascal']

'''

 



answered Jan 13, 2020 by avibootz
...