Run through folder add files with a certain extension to a list - Python Oneliner

Mon 26 March 2012 by Frank Lazzarini

Here is great Python Oneliner I came across, to put a list of files ending with a certain extension or name to a list, all this in just one line...

import os

list = []
list += [each for each in os.listdir('path/to/files') if each.endswith('.jpg')]