我有这个列表理解,如果它们不在列表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"]]
答案 0 :(得分:5)
你只是缺少一个i
nfld_rrop = [i for i in lst_fcflds if i not in RROPFields and i not in ["OBJECTID","SHAPE"]]
^
但是为了提高性能,我会首先添加一步来创建set
,以便您可以更快地进行成员资格查找。
filters = set(RROPFields + ["OBJECTID", "SHAPE"])
nfld_rrop = [i for i in lst_fcflds if i not in filters]