to_convert_files = [FileEnc(filename, getEncoding(filename)) for
filename in filenames if getEncoding(filename) != None]
The problem here is that getEncoding
gets called twice for each accepted file name: once in the if
clause and once in the expression preceding for
. I know I can avoid this by splitting this into a generator expression that does the mapping
and a list comprehension that does the filtering
, but I was wondering if there is a way keeping it condensed in a one-liner.