I am trying to populate a list called images
with files that have the extensions '.png'
, '.jpg'
or 'jpeg'
in a one line for loop. I tried this by using the logical or
operator but that only resulted in an empty list.
images = [i for i in os.listdir('.') if i[-4:] == ('.png' or '.jpg' or 'jpeg')]
How do I check to see if '.png'
, '.jpg'
or 'jpeg'
are the last 4 characters of the file while keeping it all in a one line for loop?