def find_files(directory, pattern):
for root, dirs, files in os.walk(directory):
for basename in files:
if fnmatch.fnmatch(basename.lower(), pattern):
filename = os.path.join(root, basename)
Its copied from stackoverflow, but it shows a really good example on when to use yield. Basically it returns a generator and thats far more memory efficient than returning a list.