If you take the code:
import os
directory = [files for root, dirs, files in os.walk(".")]
imgs = [file[0] for file in [[directory[x][y] for y,file in enumerate(dirs) if file.split('.')[1] == "png"] for x,dirs in enumerate(directory)] if len(file) != 0]
which is four for loops finding all the .png files in a directory and creating a list from the results. My question is: strictly on efficiency of the code, would this be more or less efficient than:
import os
imgs = []
directory = []
for root,dirs,file in os.walk("."):
directory.append(file)
for x,dirs in enumerate(directory):
for y,file in enumerate(dirs):
if file.split('.')[1] == "png":
imgs.append(file)
Sorry if the answer is obvious, I have never considered efficiency in a program before really. Any explanations would be much appreciated :)