I am trying to replace parts of file extensions in a list of files. I would like to be able to loop through items (files), and remove the extensions. I don\'t know how to ap
You can try this:
import re file_lst = ['cats1.fa', 'cats2.fa', 'dog1.fa', 'dog2.fa'] final_list = [re.sub('\d+\.\w+$', '', i) for i in file_lst]
Output:
['cats', 'cats', 'dog', 'dog']