简体   繁体   English

python:如何获取数组中除条件以外的所有成员

[英]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.

相关问题 如何获取属于Python 3中特定类的所有属性(继承的属性除外)的值 - How to get values of all properties (except inherited ones) that belong to specific class in Python 3 如何打印所有已定义的变量,除了等于0的变量 - Python3 - How to print all defined variables except for the ones that are equal to 0 - Python3 如何在Python上匹配除下划线之外的所有字母数字 - How to match all alphanumeric except underscore on Python 如何按顺序获取 python 中 class 的所有成员? - How to get all members of a class in python in order? 除Python列表中指定的列外的所有列的总和 - Sum of all columns except the ones specified in a list in Python 删除所有数字,除了使用 python regex 组合成字符串的数字 - Remove all numbers except for the ones combined to string using python regex 使用pathlib递归获取除隐藏文件之外的所有文件 - recursively get all files except the hidden ones with pathlib 如何使用 Python 3 脚本在浏览器中获取所有存储的 cookie? - How to get all stored cookies in ones browser with a Python 3 script? 匹配的html <form> 与python regex一起使用,但“ get”除外 - matching html <form> with python regex except the “get” ones 如何缩放除 pandas dataframe 中的某些列之外的所有列? - How to scale all columns except certain ones in pandas dataframe?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM