As part of my project, my tool asks the user to input a folder, all the files contained in the folder are stored in a list and used later. I need to make it so that the list will only contain files which are of the ".jpg" or ".tiff" file format, therefore removing any files which are not of that file format. I cannot seem to figure out how to do this. How do I go about removing any other file formats from the list? I will post below one example of what I have already tried.
files = os.listdir(file_dir)
for file in files:
if not files.endswith(".jpg", ".tiff"):
files = files.remove(file)