[英]python: how to get all members of an array except for ones that match a condition
I'm trying to create an array of all .asm files I need to build except for one that is causing me trouble right now. 我正在尝试创建一个我需要构建的所有.asm文件的数组, 除了其中一个会给我带来麻烦的文件。 Here's what I have, based on the Scons "Handling Common Cases" page:
根据Scons的“处理常见案例”页面,这是我所拥有的:
projfiles['buildasm'] =
['#build/'+os.path.splitext(x)[0]+'.asm' for x in projfiles['a']];
(this maps paths of the form 'foo.a' to '#build/foo.asm') (这会将格式为“ foo.a”的路径映射到“#build / foo.asm”)
I want to run this for each member of projfiles['a']
except if a member of the array matches 'baz.a'. 我要为
projfiles['a']
每个成员运行此命令, 除非数组的成员与'baz.a'匹配。 How can I do this? 我怎样才能做到这一点?
projfiles['buildasm'] = ['#build/'+os.path.splitext(x)[0]+'.asm' for x in projfiles['a'] if x != 'baz.a']
or more generally: 或更一般而言:
ignored_files = ['baz.a',
'foo.a',
'xyzzy.a',
]
projfiles['buildasm'] = ['#build/'+os.path.splitext(x)[0]+'.asm' for x in projfiles['a'] if x not in ignored_files]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.