我有这个列表理解,它返回列表 lst_fcflds
中的元素,如果它们不在列表 RROPFields
中:
nfld_rrop = [i for i in lst_fcflds if i not in RROPFields]
并且想要一个过滤器,这样如果 OBJECTID
或 SHAPE
在 lst_fclfds 中,它们也不会被返回 - 比如:
nfld_rrop = [i for i in lst_fcflds if i not in RROPFields and not in ["OBJECTID","SHAPE"]]
最佳答案
你只是少了一个i
nfld_rrop = [i for i in lst_fcflds if i not in RROPFields and i not in ["OBJECTID","SHAPE"]]
^
但是为了提高性能,我会先添加一个步骤来创建一个集合
,这样您就可以更快地进行成员查找。
filters = set(RROPFields + ["OBJECTID", "SHAPE"])
nfld_rrop = [i for i in lst_fcflds if i not in filters]
关于python - 如何使用多个条件过滤 Python 列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30919430/