8 行のコードをわずか 2 行に変換することができました。
最初のリスト内包表記はフォルダーを取得し、2 番目のリスト内包表記は特定のフィルターのファイルを取得します。
hideTheseFolders=[".thumb",".mayaSwatches","RECYCLER","$AVG"]
fileFilters=["ma","jpg","png","mb",'iff','tga','tif']
newLst=[]
import os
locationTxt="E:\box\scripts"
[newLst.append(each) for each in os.listdir(locationTxt) if os.path.isdir(os.path.join(locationTxt,each)) and each not in hideTheseFolders]
[newLst.append(os.path.basename(os.path.join(locationTxt,each))) for nfile in fileFilters for each in os.listdir(locationTxt) if each.endswith(nfile)]
上記のコードでは、最後の 2 行が から同じディレクトリ内を参照していlocationTxt
ます。つまり、最後の 2 行をマージできる方法がある可能性があります。助言がありますか?