如何从集合中提取、修改单个元素并提供给函数?

How to extract, modify single element from set and provide to function?

如何从set/list中提取元素并一次性直接提供给shutil.ignore_patterns?

虚拟代码:

import shutil

patterns = set(
    [
        "A",
        "B",
        "C"
    ]
)
def exclusion_policy():
    return shutil.ignore_patterns('*' + x + '*' for x in (*patterns))

另一种选择是 - 这可行:

def exclusion_policy():
    return shutil.ignore_patterns('*A*', '*B*', '*C*')

就这样:

import shutil

patterns = set(["A", "B", "C"])


def exclusion_policy():
    return shutil.ignore_patterns(*('*' + x + '*' for x in patterns))

* 将 sequence/collection 解包为位置参数,在本例中序列为 ('*' + x + '*' for x in patterns)