gpt4 book ai didi

python - 如何在 map 中将项目作为参数列表传递?

转载 作者:太空宇宙 更新时间:2023-11-04 06:53:47 24 4
gpt4 key购买 nike

这是我的一段代码。 Lambda 接受 3 个参数,我想将它们作为位置参数的元组传递,但显然 map 将它们作为单个参数提供。

如何在底部提供那些元组作为参数列表? (我知道我可以重写 lambda,但它的可读性会变得不好)

 adds = map((lambda j, f, a:
j.join([f.format(i) for i in parse.options[a]]) if parse.options[a] else ''),
((' ', ' -not -path "{0}" ', 'exclude'),
(' -or ', '-path "{0}"', 'include')))

最佳答案

map()描述:

map(function, iterable, ...)

Apply function to every item of iterable and return a list of the results. If additional iterable arguments are passed, function must take that many arguments and is applied to the items from all iterables in parallel. If one iterable is shorter than another it is assumed to be extended with None items. If function is None, the identity function is assumed; if there are multiple arguments, map() returns a list consisting of tuples containing the corresponding items from all iterables (a kind of transpose operation). The iterable arguments may be a sequence or any iterable object; the result is always a list.

您需要将参数放在并行列表或元组中,并将它们传递给 map()作为 3 个可迭代对象。

关于python - 如何在 map 中将项目作为参数列表传递?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1858720/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com