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

标签 python dictionary arguments

这是我的一段代码。 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/

相关文章:

当键为 "numeric string"时的 python ordereddict

python - 如何创建一个字典,将重复值映射到多个键并清理数据?

c# - 通用参数列表

python - Tkinter 格式化为小数点后两位

Python:使用字典来表示 matplotlib 颜色和阴影

vb.net - 如何从vb.net中的命令行发送Yes参数以覆盖计划

c++ - 将 byte[] 数组作为方法的多个参数传递

python - 查找 Redis 中值最高的前 N ​​个键

python - TFLearn:仅使用 tflearn 创建训练测试集

python - 如何在 .py 文件中使用 Matplotlib 在绘图的图例中编写 Latex 公式?