我想知道是否有可能取代这个:如果列表理解中的列表元素条件
results = [x for x in os.listdir(dir_path) if os.path.splitext(x)[1] == ".tif" and "abc" in os.path.splitext(x)[0]]
的东西,如:
results = [x for x in os.listdir(dir_path) if ext == ".tif" and "abc" in name for ext, name in os.path.splitext(x)]
感谢您的帮助
什么是''abc“名字为ext,名字在os.path.splitext(x)'假设是指?你想在这里完成什么? –
你的意思是:'[x for os.listdir(dir_path)if ext ==“.tif”and“abc”in os.path.splitext(x)[1]]'??? –
@ juanpa.arrivillaga是的,谢谢,我的意思是相反。而“abc”只是一个任意的名字。我试图列出所有在文件名中有“abc”的文件,同时有扩展名“.tif” – MMagician