How to replace substring in list of strings with Python

1 Answer

0 votes
lst = ['java', 'python', 'php', 'java', 'nodejs'] 
  
lst = [sub.replace('th', 'SUB') for sub in lst] 

print(lst)
      

        
'''
run:
 
['java', 'pySUBon', 'php', 'java', 'nodejs']
        
'''

 



answered May 1, 2020 by avibootz
edited May 1, 2020 by avibootz
...